Skip to content

Commit

Permalink
fix #1469
Browse files Browse the repository at this point in the history
  • Loading branch information
doits committed Aug 16, 2024
1 parent 59c3300 commit 27ecc51
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/good_job/active_job_extensions/concurrency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ def deserialize(job_data)
.order(Arel.sql("COALESCE(performed_at, scheduled_at, created_at) ASC"))
.limit(limit).pluck(:active_job_id)
# The current job has already been locked and will appear in the previous query
exceeded = :limit unless allowed_active_job_ids.include?(job.job_id)
next
unless allowed_active_job_ids.include?(job.job_id)
exceeded = :limit
next
end
end

if throttle
Expand Down
32 changes: 32 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 @@ -214,6 +214,38 @@ def perform
expect(GoodJob::Job.finished.count).to eq 3
end
end

describe 'perform_limit: together with perform_throttle:' do
before do
allow(GoodJob).to receive(:preserve_job_records).and_return(true)

TestJob.good_job_control_concurrency_with(
perform_limit: -> { 1 },
perform_throttle: -> { [1, 1.minute] },
key: -> { arguments.first[:name] }
)
end

it 'does not perform if throttle period has not passed' do
TestJob.perform_later(name: "Alice")
TestJob.perform_later(name: "Alice")
TestJob.perform_later(name: "Alice")
GoodJob.perform_inline

expect(GoodJob::Job.finished.count).to eq 1

Timecop.travel(61.seconds)
TestJob.perform_later(name: "Alice")
GoodJob.perform_inline

expect(GoodJob::Job.finished.count).to eq 2

Timecop.travel(61.seconds)
GoodJob.perform_inline

expect(GoodJob::Job.finished.count).to eq 3
end
end
end

describe '#good_job_concurrency_key' do
Expand Down

0 comments on commit 27ecc51

Please sign in to comment.