Skip to content

Commit

Permalink
Ensure concurrency controls are ignored when perform_now inside ano…
Browse files Browse the repository at this point in the history
…ther job
  • Loading branch information
bensheldon committed Apr 23, 2024
1 parent 410b34f commit 4a63683
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/good_job/active_job_extensions/concurrency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def deserialize(job_data)
key = job.good_job_concurrency_key
next if key.blank?

if CurrentThread.execution.blank?
if CurrentThread.execution.blank? || CurrentThread.execution.active_job_id != job_id
logger.debug("Ignoring concurrency limits because the job is executed with `perform_now`.")
next
end
Expand Down
1 change: 1 addition & 0 deletions sorbet/rbi/todo.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module ::TestJob::Error; end
module ::TestJob::ExpectedError; end
module ::TestJob::RunError; end
module ::TestJob::SuccessCallbackJob; end
module ::WrapperJob; end
module GoodJob::Job::ERROR_EVENT_INTERRUPTED; end
module GoodJob::Job::ERROR_EVENT_RETRIED; end
module Rails::Server; end
12 changes: 12 additions & 0 deletions spec/lib/good_job/active_job_extensions/concurrency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ def perform(name:)
TestJob.perform_now(name: "Alice")
expect(JOB_PERFORMED).to be_true
end

it 'is ignored when the job is executed inside another job' do
stub_const("WrapperJob", Class.new(ApplicationJob) do
def perform
TestJob.perform_now(name: "Alice")
end
end)

WrapperJob.perform_later
GoodJob.perform_inline
expect(JOB_PERFORMED).to be_true
end
end

describe '#enqueue_throttle' do
Expand Down

0 comments on commit 4a63683

Please sign in to comment.