Class: Joblin::Uniqueness::Strategy::Base
- Inherits:
-
Object
- Object
- Joblin::Uniqueness::Strategy::Base
show all
- Defined in:
- lib/joblin/uniqueness/strategy/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(lock_context) ⇒ Base
Returns a new instance of Base.
6
7
8
9
|
# File 'lib/joblin/uniqueness/strategy/base.rb', line 6
def initialize(lock_context)
@lock_context = lock_context
@conflict_strategies = {}
end
|
Instance Attribute Details
#lock_context ⇒ Object
Returns the value of attribute lock_context.
4
5
6
|
# File 'lib/joblin/uniqueness/strategy/base.rb', line 4
def lock_context
@lock_context
end
|
Class Method Details
.internal_batch_callback(batch_status, opts) ⇒ Object
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/joblin/uniqueness/strategy/base.rb', line 72
def self.internal_batch_callback(batch_status, opts)
Joblin::Uniqueness.logger.debug("Received Batch(#{batch_status.bid}) callback for #{opts[:lock_strategy]} #{opts[:lock_key]} - #{opts[:event]}")
Joblin::Uniqueness.logger.debug("Context data: #{opts[:lock_context]}")
strategy_class = opts[:lock_strategy].constantize
lock_context = LockContext.from_serialized(opts[:lock_context])
Joblin::Uniqueness.logger.debug("Rehydrated LockContext: #{lock_context.lock_id} #{lock_context.debug_data}")
strategy = strategy_class.new(lock_context)
strategy.batch_callback(opts[:event].to_sym, batch_status)
end
|
.locks_on(*origins) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/joblin/uniqueness/strategy/base.rb', line 13
def self.locks_on(*origins)
if origins.present?
orgins = Array(origins).map(&:to_sym)
self._locks_on = origins
else
self._locks_on || [:enqueue, :perform]
end
end
|
Instance Method Details
#batch_callback(event, batch_status) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/joblin/uniqueness/strategy/base.rb', line 25
def batch_callback(event, batch_status)
if event == :success
unlock
else
unlock_cond = lock_context.config[:unlock_on_failure]
if (event == :complete && unlock_cond == :any) || (event == :death && unlock_cond == :death) || (event == :stagnated && unlock_cond == :stagnant)
unlock
end
end
end
|
#on_enqueue ⇒ Object
22
|
# File 'lib/joblin/uniqueness/strategy/base.rb', line 22
def on_enqueue; end
|
23
|
# File 'lib/joblin/uniqueness/strategy/base.rb', line 23
def on_perform; end
|