Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #4258

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Test #4258

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/jobs/generic_enqueuer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Jobs
class GenericEnqueuer < Enqueuer
def self.shared(priority: nil)
stored_instance = Thread.current[:generic_enqueuer]
puts "[#{Process.pid} | #{Thread.current.object_id}] Shared enqueuer accessed: #{stored_instance} | Priority: #{priority}"
return stored_instance if stored_instance && priority.nil?

new_instance = new(queue: Jobs::Queues.generic, priority: priority)
Expand All @@ -13,6 +14,7 @@ def self.shared(priority: nil)
end

def self.reset!
puts "Resetting GenericEnqueuer instance #{Thread.current[:generic_enqueuer]} in process: #{Process.pid} | Thread: #{Thread.current.object_id}"
Thread.current[:generic_enqueuer] = nil
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/reoccurring_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def expire!
def enqueue_next_job(pollable_job)
run_at = Delayed::Job.db_time_now + next_execution_in
@retry_number += 1
puts "Enqueuing next job for #{self.class} with guid: #{pollable_job.guid} at #{run_at}"
puts "Using generic enqueuer: #{Thread.current[:generic_enqueuer]} in process: #{Process.pid} | Thread: #{Thread.current.object_id}"
Jobs::GenericEnqueuer.shared.enqueue_pollable(self, existing_guid: pollable_job.guid, run_at: run_at, preserve_priority: true)
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/jobs/generic_enqueuer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def perform

before do
# Reset singleton instance to ensure clean tests
Thread.current[:generic_enqueuer] = nil
puts 'Resetting GenericEnqueuer instance in before'
GenericEnqueuer.reset!
end

describe '.shared' do
Expand Down
3 changes: 3 additions & 0 deletions spec/unit/jobs/reoccurring_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ def perform

it 'keeps the delayed job\'s priority when re-enqueuing' do
TestConfig.config[:jobs][:priorities] = { 'fake-job': 20 }
Jobs::GenericEnqueuer.shared # ensure the enqueuer is created and the same instance is used

pollable_job = Jobs::Enqueuer.new({ queue: Jobs::Queues.generic, priority: 22 }).enqueue_pollable(FakeJob.new)
puts("All jobs before executing: #{Delayed::Job.all}")
expect(Delayed::Job.where(guid: PollableJobModel.first.delayed_job_guid).first[:priority]).to eq(42)

execute_all_jobs(expected_successes: 1, expected_failures: 0, jobs_to_execute: 1)
puts("All jobs after executing: #{Delayed::Job.all}")

expect(Delayed::Job.where(guid: PollableJobModel.first.delayed_job_guid).first[:priority]).to eq(42)
expect(PollableJobModel.first.delayed_job_guid).not_to eq(pollable_job.delayed_job_guid)
Expand Down
Loading