Class: Jidoka::Supervisor

Inherits:
Worker
  • Object
show all
Defined in:
lib/jidoka/supervisor.rb,
lib/jidoka/supervisor/step.rb

Defined Under Namespace

Classes: Step

Constant Summary

Constants inherited from Worker

Worker::BASE_ERRORS, Worker::ERRORS

Instance Attribute Summary

Attributes inherited from Worker

#error, #message

Instance Method Summary collapse

Methods inherited from Worker

#_notify, dry_run, dry_run!, enforce_arguments!, #failed, #failure?, include_notify?, initialize_and_call!, #perform, possible_errors, #prepare, run, #run, run!, #success, #success?, undo, #undo, undo!, #undo!, #up, #validate, #validate!, #with_transaction

Constructor Details

#initialize(*args) ⇒ Supervisor

Returns a new instance of Supervisor.



5
6
7
8
# File 'lib/jidoka/supervisor.rb', line 5

def initialize(*args)
  super(*args)
  @steps = []
end

Instance Method Details

#downObject

Alias for compatibility



31
32
33
# File 'lib/jidoka/supervisor.rb', line 31

def down
  rollback
end

#notify!Object



35
36
37
38
39
40
41
# File 'lib/jidoka/supervisor.rb', line 35

def notify!
  @steps.each(&:_notify)
  _notify(**@opts)
rescue StandardError => e
  report_error(e)
  raise(e) if defined?(Rails) && Rails.env.test?
end

#rollbackObject



20
21
22
23
24
25
26
27
28
# File 'lib/jidoka/supervisor.rb', line 20

def rollback
  @steps.reverse_each do |step|
    begin
      step._down
    rescue StandardError => e
      report_error(e)
    end
  end
end

#run!Object



10
11
12
13
14
15
16
17
18
# File 'lib/jidoka/supervisor.rb', line 10

def run!
  orchestrate(**@opts)
rescue StandardError => e
  rollback
  # notice_failure! is called in run! wrapper of super, but we need to ensure
  # we notice it here if we want to log it before re-raising
  send(:notice_failure!, e)
  raise(e)
end