Skip to content

Commit

Permalink
Deprecate GoodJob::Lockable and rename to `GoodJob::AdvisoryLockable (
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon committed Jul 27, 2023
1 parent 58a49ea commit 573ec04
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module GoodJob
# end
# end
#
module Lockable
module AdvisoryLockable
extend ActiveSupport::Concern

# Indicates an advisory lock is already held on a record by another
Expand Down
2 changes: 1 addition & 1 deletion app/models/good_job/base_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module GoodJob
# ActiveRecord model to share behavior between {Job} and {Execution} models
# which both read out of the same table.
class BaseExecution < BaseRecord
include AdvisoryLockable
include ErrorEvents
include Filterable
include Lockable
include Reportable

self.table_name = 'good_jobs'
Expand Down
2 changes: 1 addition & 1 deletion app/models/good_job/batch_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module GoodJob
class BatchRecord < BaseRecord
include Lockable
include AdvisoryLockable

self.table_name = 'good_job_batches'

Expand Down
2 changes: 1 addition & 1 deletion app/models/good_job/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
module GoodJob # :nodoc:
# ActiveRecord model that represents an GoodJob process (either async or CLI).
class Process < BaseRecord
include AdvisoryLockable
include AssignableConnection
include Lockable

# Interval until the process record being updated
STALE_INTERVAL = 30.seconds
Expand Down
3 changes: 3 additions & 0 deletions lib/good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def self.deprecator
end
end

include ActiveSupport::Deprecation::DeprecatedConstantAccessor
deprecate_constant :Lockable, 'GoodJob::AdvisoryLockable', deprecator: deprecator

# Whether all GoodJob migrations have been applied.
# For use in tests/CI to validate GoodJob is up-to-date.
# @return [Boolean]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe GoodJob::Lockable do
RSpec.describe GoodJob::AdvisoryLockable do
let(:model_class) { GoodJob::Execution }
let!(:execution) { model_class.create(active_job_id: SecureRandom.uuid, queue_name: "default") }

Expand Down Expand Up @@ -318,7 +318,7 @@

expect do
Concurrent::Promises.future(execution, &:advisory_lock!).value!
end.to raise_error GoodJob::Lockable::RecordAlreadyAdvisoryLockedError
end.to raise_error GoodJob::AdvisoryLockable::RecordAlreadyAdvisoryLockedError

execution.advisory_unlock
end
Expand Down
2 changes: 1 addition & 1 deletion spec/app/models/good_job/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def perform
job.with_advisory_lock do
expect do
Concurrent::Promises.future(job, &:retry_job).value!
end.to raise_error GoodJob::Lockable::RecordAlreadyAdvisoryLockedError
end.to raise_error GoodJob::AdvisoryLockable::RecordAlreadyAdvisoryLockedError
end
end
end
Expand Down

0 comments on commit 573ec04

Please sign in to comment.