Skip to content

Commit

Permalink
Limit query for allowed concurrent jobs to unfinished (#515)
Browse files Browse the repository at this point in the history
This allows it to make use of the index
index_good_jobs_on_concurrency_key_when_unfinished.

Refs bensheldon/good_job#514
  • Loading branch information
OneDev0411 committed Feb 7, 2022
1 parent 3c47866 commit 2ff13e3
Showing 1 changed file with 1 addition 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 @@ -62,7 +62,7 @@ def backtrace
next if key.blank?

GoodJob::Execution.advisory_lock_key(key, function: "pg_advisory_lock") do
allowed_active_job_ids = GoodJob::Execution.where(concurrency_key: key).advisory_locked.order(Arel.sql("COALESCE(performed_at, scheduled_at, created_at) ASC")).limit(perform_limit).pluck(:active_job_id)
allowed_active_job_ids = GoodJob::Execution.unfinished.where(concurrency_key: key).advisory_locked.order(Arel.sql("COALESCE(performed_at, scheduled_at, created_at) ASC")).limit(perform_limit).pluck(:active_job_id)
# The current job has already been locked and will appear in the previous query
raise GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError unless allowed_active_job_ids.include? job.job_id
end
Expand Down

0 comments on commit 2ff13e3

Please sign in to comment.