Class: ActiveJob::Uniqueness::Strategies::Base
- Inherits:
-
Object
- Object
- ActiveJob::Uniqueness::Strategies::Base
- Defined in:
- lib/active_job/uniqueness/strategies/base.rb
Overview
Base strategy is not supposed to actually be used as uniqueness strategy.
Direct Known Subclasses
UntilAndWhileExecuting, UntilExecuted, UntilExecuting, UntilExpired, WhileExecuting
Defined Under Namespace
Modules: LockingOnEnqueue
Constant Summary collapse
- ACTIVEJOB_SUPPORTS_THROW_ABORT =
ActiveJob.gem_version >= Gem::Version.new('5.0')
Instance Attribute Summary collapse
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#lock_key ⇒ Object
readonly
Returns the value of attribute lock_key.
-
#lock_ttl ⇒ Object
readonly
Returns the value of attribute lock_ttl.
-
#on_conflict ⇒ Object
readonly
Returns the value of attribute on_conflict.
Instance Method Summary collapse
- #after_perform ⇒ Object
- #around_enqueue(block) ⇒ Object
- #around_perform(block) ⇒ Object
- #before_enqueue ⇒ Object
- #before_perform ⇒ Object
-
#initialize(job:) ⇒ Base
constructor
A new instance of Base.
- #lock(resource:, ttl:, event: :lock) ⇒ Object
- #unlock(resource:, event: :unlock) ⇒ Object
Constructor Details
#initialize(job:) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 16 def initialize(job:) @lock_key = job.lock_key @lock_ttl = (job.[:lock_ttl] || config.lock_ttl).to_i * 1000 # ms @on_conflict = job.[:on_conflict] || config.on_conflict @job = job end |
Instance Attribute Details
#job ⇒ Object (readonly)
Returns the value of attribute job.
14 15 16 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 14 def job @job end |
#lock_key ⇒ Object (readonly)
Returns the value of attribute lock_key.
14 15 16 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 14 def lock_key @lock_key end |
#lock_ttl ⇒ Object (readonly)
Returns the value of attribute lock_ttl.
14 15 16 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 14 def lock_ttl @lock_ttl end |
#on_conflict ⇒ Object (readonly)
Returns the value of attribute on_conflict.
14 15 16 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 14 def on_conflict @on_conflict end |
Instance Method Details
#after_perform ⇒ Object
53 54 55 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 53 def after_perform # Expected to be overriden in the descendant strategy end |
#around_enqueue(block) ⇒ Object
43 44 45 46 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 43 def around_enqueue(block) # Expected to be overriden in the descendant strategy block.call end |
#around_perform(block) ⇒ Object
48 49 50 51 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 48 def around_perform(block) # Expected to be overriden in the descendant strategy block.call end |
#before_enqueue ⇒ Object
35 36 37 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 35 def before_enqueue # Expected to be overriden in the descendant strategy end |
#before_perform ⇒ Object
39 40 41 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 39 def before_perform # Expected to be overriden in the descendant strategy end |
#lock(resource:, ttl:, event: :lock) ⇒ Object
23 24 25 26 27 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 23 def lock(resource:, ttl:, event: :lock) lock_manager.lock(resource, ttl).tap do |result| instrument(event, resource: resource, ttl: ttl) if result end end |
#unlock(resource:, event: :unlock) ⇒ Object
29 30 31 32 33 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 29 def unlock(resource:, event: :unlock) lock_manager.delete_lock(resource).tap do instrument(event, resource: resource) end end |