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.
-
#on_redis_connection_error ⇒ Object
readonly
Returns the value of attribute on_redis_connection_error.
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 22 |
# 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 @on_redis_connection_error = job.[:on_redis_connection_error] || config.on_redis_connection_error @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 |
#on_redis_connection_error ⇒ Object (readonly)
Returns the value of attribute on_redis_connection_error.
14 15 16 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 14 def on_redis_connection_error @on_redis_connection_error end |
Instance Method Details
#after_perform ⇒ Object
54 55 56 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 54 def after_perform # Expected to be overriden in the descendant strategy end |
#around_enqueue(block) ⇒ Object
44 45 46 47 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 44 def around_enqueue(block) # Expected to be overriden in the descendant strategy block.call end |
#around_perform(block) ⇒ Object
49 50 51 52 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 49 def around_perform(block) # Expected to be overriden in the descendant strategy block.call end |
#before_enqueue ⇒ Object
36 37 38 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 36 def before_enqueue # Expected to be overriden in the descendant strategy end |
#before_perform ⇒ Object
40 41 42 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 40 def before_perform # Expected to be overriden in the descendant strategy end |
#lock(resource:, ttl:, event: :lock) ⇒ Object
24 25 26 27 28 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 24 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
30 31 32 33 34 |
# File 'lib/active_job/uniqueness/strategies/base.rb', line 30 def unlock(resource:, event: :unlock) lock_manager.delete_lock(resource).tap do instrument(event, resource: resource) end end |