Skip to content

Commit

Permalink
Add temporary additional lock on good_jobs-[active_job_id] (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon committed Aug 24, 2021
1 parent caf555c commit 3045201
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/good_job/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ def self.perform_with_advisory_lock
break if good_job.blank?
break :unlocked unless good_job&.executable?

good_job.perform
begin
good_job.with_advisory_lock(key: "good_jobs-#{good_job.active_job_id}") do
good_job.perform
end
rescue RecordAlreadyAdvisoryLockedError => e
ExecutionResult.new(value: nil, handled_error: e)
end
end
end

Expand Down
4 changes: 3 additions & 1 deletion spec/integration/scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
def perform(*_args, **_kwargs)
thread_name = Thread.current.name || Thread.current.object_id

expected_locks_per_thread = 2 # TODO: Temporary value for GoodJob v1.99. Should be reduced to 1 for GoodJob 2.0.

locks_count = PgLock.advisory_lock.owns.count
if locks_count > 1
if locks_count > expected_locks_per_thread
puts "Thread #{thread_name} owns #{locks_count} locks."

puts "GoodJobs locked by this connection:"
Expand Down

0 comments on commit 3045201

Please sign in to comment.