Class: Resque::JobChain::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/job_chain/executor.rb

Instance Method Summary collapse

Constructor Details

#initialize(chain_id, step_index) ⇒ Executor

Returns a new instance of Executor.



4
5
6
7
# File 'lib/resque/job_chain/executor.rb', line 4

def initialize(chain_id, step_index)
  @chain_id = chain_id
  @step_index = step_index
end

Instance Method Details

#after_stepObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/resque/job_chain/executor.rb', line 9

def after_step
  result = Persistence.advance(@chain_id, @step_index)

  case result
  when 'completed'
    Observable.notify(:chain_completed, @chain_id)
  when 'advanced'
    enqueue_next_step
    Observable.notify(:step_completed, @chain_id, @step_index)
  when 'stale'
    Observable.notify(:step_stale, @chain_id, @step_index)
  end

  result
end

#on_failure(error) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/resque/job_chain/executor.rb', line 25

def on_failure(error)
  step = Persistence.load_step(@chain_id, @step_index)
  strategy = resolve_strategy(step)
  max_attempts = step.max_attempts || JobChain.configuration.default_max_attempts

  result = Persistence.fail_step(
    @chain_id, @step_index, error.message, strategy, max_attempts
  )

  handle_failure_result(result, step)
end