Class: Proxy::Dynflow::Runner::Dispatcher::RunnerActor

Inherits:
Dynflow::Actor
  • Object
show all
Defined in:
lib/smart_proxy_dynflow/runner/dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher, suspended_action, runner, clock, logger, _options = {}) ⇒ RunnerActor

Returns a new instance of RunnerActor.



16
17
18
19
20
21
22
23
24
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 16

def initialize(dispatcher, suspended_action, runner, clock, logger, _options = {})
  @dispatcher = dispatcher
  @clock = clock
  @ticker = dispatcher.ticker
  @logger = logger
  @suspended_action = suspended_action
  @runner = runner
  @finishing = false
end

Instance Method Details

#dispatch_updates(updates) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 54

def dispatch_updates(updates)
  updates.each { |receiver, update| (receiver || @suspended_action) << update }

  # This is a workaround when the runner does not accept the suspended action
  main_key = updates.keys.any?(&:nil?) ? nil : @suspended_action
  main_process = updates[main_key]
  finish if main_process&.exit_status
end

#external_event(event) ⇒ Object



90
91
92
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 90

def external_event(event)
  dispatch_updates(@runner.external_event(event))
end

#finishObject



77
78
79
80
81
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 77

def finish
  @logger.debug("finish runner #{@runner.id}")
  @finishing = true
  @dispatcher.finish(@runner.id)
end

#killObject



70
71
72
73
74
75
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 70

def kill
  @logger.debug("kill runner #{@runner.id}")
  @runner.kill
rescue => e
  handle_exception(e, false)
end

#on_envelope(*args) ⇒ Object



26
27
28
29
30
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 26

def on_envelope(*args)
  super
rescue => e
  handle_exception(e)
end

#refresh_outputObject



49
50
51
52
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 49

def refresh_output
  @logger.debug("refresh output #{@runner.id}")
  dispatch_updates(@runner.run_refresh_output)
end

#refresh_runnerObject



41
42
43
44
45
46
47
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 41

def refresh_runner
  @logger.debug("refresh runner #{@runner.id}")
  dispatch_updates(@runner.run_refresh)
ensure
  @refresh_planned = false
  plan_next_refresh
end

#start_runnerObject



32
33
34
35
36
37
38
39
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 32

def start_runner
  @logger.debug("start runner #{@runner.id}")
  set_timeout if @runner.timeout_interval
  @runner.start
  refresh_runner
ensure
  plan_next_refresh
end

#start_termination(*args) ⇒ Object



83
84
85
86
87
88
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 83

def start_termination(*args)
  @logger.debug("terminate #{@runner.id}")
  super
  @runner.close
  finish_termination
end

#timeout_runnerObject



63
64
65
66
67
68
# File 'lib/smart_proxy_dynflow/runner/dispatcher.rb', line 63

def timeout_runner
  @logger.debug("timeout runner #{@runner.id}")
  @runner.timeout
rescue => e
  handle_exception(e, false)
end