Class: Cloudtasker::UniqueJob::Lock::BaseLock
- Inherits:
-
Object
- Object
- Cloudtasker::UniqueJob::Lock::BaseLock
- Defined in:
- lib/cloudtasker/unique_job/lock/base_lock.rb
Overview
Base behaviour for locks
Direct Known Subclasses
Instance Attribute Summary collapse
-
#job ⇒ Object
readonly
Returns the value of attribute job.
Instance Method Summary collapse
-
#conflict_instance ⇒ Cloudtasker::UniqueJob::ConflictStrategy::BaseStrategy
Return the conflict strategy to use on conflict.
-
#default_conflict_strategy ⇒ Cloudtasker::UniqueJob::ConflictStrategy::BaseStrategy
Return the strategy to use by default.
-
#execute ⇒ Object
Lock logic invoked when a job is executed (server middleware).
-
#initialize(job) ⇒ BaseLock
constructor
Build a new instance of the class.
-
#options ⇒ Hash
Return the worker configuration options.
-
#schedule ⇒ Object
Lock logic invoked when a job is scheduled (client middleware).
Constructor Details
#initialize(job) ⇒ BaseLock
Build a new instance of the class.
15 16 17 |
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 15 def initialize(job) @job = job end |
Instance Attribute Details
#job ⇒ Object (readonly)
Returns the value of attribute job.
8 9 10 |
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 8 def job @job end |
Instance Method Details
#conflict_instance ⇒ Cloudtasker::UniqueJob::ConflictStrategy::BaseStrategy
Return the conflict strategy to use on conflict
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 42 def conflict_instance @conflict_instance ||= begin # Infer lock class and get instance strategy_name = [:on_conflict] strategy_klass = ConflictStrategy.const_get(strategy_name.to_s.split('_').collect(&:capitalize).join) strategy_klass.new(job) rescue NameError default_conflict_strategy.new(job) end end |
#default_conflict_strategy ⇒ Cloudtasker::UniqueJob::ConflictStrategy::BaseStrategy
Return the strategy to use by default. Can be overriden in each lock.
33 34 35 |
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 33 def default_conflict_strategy ConflictStrategy::Reject end |
#execute ⇒ Object
Lock logic invoked when a job is executed (server middleware).
64 65 66 |
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 64 def execute yield end |
#options ⇒ Hash
Return the worker configuration options.
24 25 26 |
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 24 def job. end |
#schedule ⇒ Object
Lock logic invoked when a job is scheduled (client middleware).
57 58 59 |
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 57 def schedule yield end |