Skip to content

Commit

Permalink
Fix wait and wait_until ignored in bulk enqueue (#960)
Browse files Browse the repository at this point in the history
Co-authored-by: alokhmutov <alokhmutov@gmail.com>
  • Loading branch information
bensheldon and alokhmutov committed May 21, 2023
1 parent 75e3280 commit 927655b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-capybara
- rubocop-performance
- rubocop-rails
- rubocop-rspec
Expand Down
3 changes: 1 addition & 2 deletions app/models/good_job/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,8 @@ def self.enqueue_args(active_job, overrides = {})
queue_name: active_job.queue_name.presence || DEFAULT_QUEUE_NAME,
priority: active_job.priority || DEFAULT_PRIORITY,
serialized_params: active_job.serialize,
scheduled_at: active_job.scheduled_at,
}

execution_args[:scheduled_at] = Time.zone.at(active_job.scheduled_at) if active_job.scheduled_at
execution_args[:concurrency_key] = active_job.good_job_concurrency_key if active_job.respond_to?(:good_job_concurrency_key)

reenqueued_current_execution = CurrentThread.active_job_id && CurrentThread.active_job_id == active_job.job_id
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/good_job/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ def perform(succeed: true)
expect(provider_job_ids).to all be_present
end

it 'enqueues queue_name, scheduled_at, priority' do
active_job = ExampleJob.new
active_job.queue_name = 'elephant'
active_job.priority = -55
active_job.scheduled_at = 10.minutes.from_now

adapter.enqueue_all([active_job])

expect(GoodJob::Job.last).to have_attributes(
queue_name: 'elephant',
priority: -55,
scheduled_at: be_within(0.1).of(10.minutes.from_now)
)
end

context 'when a job fails to enqueue' do
it 'does not set a provider_job_id' do
allow(GoodJob::Execution).to receive(:insert_all).and_wrap_original do |original_method, *args|
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/good_job/bulk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,17 @@ def perform
expect(job_1.provider_job_id).to be_present
expect(job_2.provider_job_id).to be_nil
end

it 'sets queue, scheduled_at, and priority' do
described_class.enqueue do
TestJob.set(queue: 'elephant', wait: 10.minutes, priority: 50).perform_later
end

expect(GoodJob::Job.last).to have_attributes(
queue_name: 'elephant',
scheduled_at: be_within(1.second).of(10.minutes.from_now),
priority: 50
)
end
end
end
2 changes: 1 addition & 1 deletion spec/test_app/app/jobs/example_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ExampleJob < ApplicationJob

TYPES = [
SUCCESS_TYPE = 'success',
ERROR_ONCE_TYPE = 'error_once',
ERROR_ONCE_TYPE = 'error_once',
ERROR_FIVE_TIMES_TYPE = 'error_five_times',
DEAD_TYPE = 'dead',
SLOW_TYPE = 'slow',
Expand Down

0 comments on commit 927655b

Please sign in to comment.