Class: Cloudtasker::UniqueJob::Lock::BaseLock

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudtasker/unique_job/lock/base_lock.rb

Overview

Base behaviour for locks

Direct Known Subclasses

NoOp, UntilExecuted, UntilExecuting, WhileExecuting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job) ⇒ BaseLock

Build a new instance of the class.

Parameters:



15
16
17
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 15

def initialize(job)
  @job = job
end

Instance Attribute Details

#jobObject (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_instanceCloudtasker::UniqueJob::ConflictStrategy::BaseStrategy

Return the conflict strategy to use on conflict

Returns:



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 = options[: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_strategyCloudtasker::UniqueJob::ConflictStrategy::BaseStrategy

Return the strategy to use by default. Can be overriden in each lock.

Returns:



33
34
35
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 33

def default_conflict_strategy
  ConflictStrategy::Reject
end

#executeObject

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

#optionsHash

Return the worker configuration options.

Returns:

  • (Hash)

    The worker configuration options.



24
25
26
# File 'lib/cloudtasker/unique_job/lock/base_lock.rb', line 24

def options
  job.options
end

#scheduleObject

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