Skip to content

Commit

Permalink
Synchronize CapsuleTracker#renew (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon authored Jun 6, 2024
1 parent 402bef7 commit 0a9b577
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/models/good_job/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def self.process_state

def refresh
self.state = self.class.process_state
reload.update(state: state, updated_at: Time.current)
reload # verify the record still exists in the database
update(state: state, updated_at: Time.current)
rescue ActiveRecord::RecordNotFound
@new_record = true
self.created_at = self.updated_at = nil
Expand Down
6 changes: 4 additions & 2 deletions lib/good_job/capsule_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ def unregister(with_advisory_lock: false)
# @param silent [Boolean] Whether to silence logging.
# @return [void]
def renew(silent: false)
GoodJob::Process.with_logger_silenced(silent: silent) do
@record&.refresh_if_stale(cleanup: true)
synchronize do
GoodJob::Process.with_logger_silenced(silent: silent) do
@record&.refresh_if_stale(cleanup: true)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/good_job/capsule_tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
end

describe '#process_id' do
it 'is a UUID' do
it 'is a UUID the process has been locked' do
expect(tracker.process_id).to be_a_uuid
end
end
Expand Down

0 comments on commit 0a9b577

Please sign in to comment.