Class: CanvasSync::JobUniqueness::Strategy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/canvas_sync/job_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/canvas_sync/job_uniqueness/strategy/base.rb', line 6

def initialize(lock_context)
  @lock_context = lock_context
  @conflict_strategies = {}
end

Instance Attribute Details

#lock_contextObject (readonly)

Returns the value of attribute lock_context.



4
5
6
# File 'lib/canvas_sync/job_uniqueness/strategy/base.rb', line 4

def lock_context
  @lock_context
end

Class Method Details

.locks_on(*origins) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/canvas_sync/job_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/canvas_sync/job_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_enqueueObject



22
# File 'lib/canvas_sync/job_uniqueness/strategy/base.rb', line 22

def on_enqueue; end

#on_performObject



23
# File 'lib/canvas_sync/job_uniqueness/strategy/base.rb', line 23

def on_perform; end