Class: Proxy::Dynflow::Action::Runner
- Inherits:
-
Shareable
- Object
- Dynflow::Action
- Shareable
- Proxy::Dynflow::Action::Runner
show all
- Includes:
- Dynflow::Action::Cancellable
- Defined in:
- lib/smart_proxy_dynflow/action/runner.rb
Instance Method Summary
collapse
Methods inherited from Shareable
#plan
Instance Method Details
#failed_run? ⇒ Boolean
72
73
74
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 72
def failed_run?
output[:exit_status] != 0
end
|
#finalize ⇒ Object
25
26
27
28
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 25
def finalize
error! 'Script execution failed' if on_proxy? && failed_run?
end
|
#finish_run(update) ⇒ Object
53
54
55
56
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 53
def finish_run(update)
output[:exit_status] = update.exit_status
output[:result] = output_result
end
|
#init_run ⇒ Object
38
39
40
41
42
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 38
def init_run
output[:result] = []
output[:runner_id] = runner_dispatcher.start(suspended_action, initiate_runner)
suspend
end
|
#initiate_runner ⇒ Object
34
35
36
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 34
def initiate_runner
raise NotImplementedError
end
|
#kill_run ⇒ Object
48
49
50
51
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 48
def kill_run
runner_dispatcher.kill(output[:runner_id])
suspend
end
|
#output_result ⇒ Object
76
77
78
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 76
def output_result
(stored_output_chunks + (@pending_output_chunks || [])).map { |c| c[:chunk] }.reduce([], &:concat)
end
|
#process_external_event(event) ⇒ Object
58
59
60
61
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 58
def process_external_event(event)
runner_dispatcher.external_event(output[:runner_id], event)
suspend
end
|
#process_update(update) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 63
def process_update(update)
output_chunk(update.continuous_output.raw_outputs) unless update.continuous_output.raw_outputs.empty?
if update.exit_status
finish_run(update)
else
suspend
end
end
|
#rescue_strategy_for_self ⇒ Object
30
31
32
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 30
def rescue_strategy_for_self
::Dynflow::Action::Rescue::Fail
end
|
#run(event = nil) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 7
def run(event = nil)
case event
when nil
init_run
when Proxy::Dynflow::Runner::Update
process_update(event)
when Proxy::Dynflow::Runner::ExternalEvent
process_external_event(event)
when ::Dynflow::Action::Cancellable::Cancel
kill_run
else
raise "Unexpected event #{event.inspect}"
end
rescue => e
action_logger.error(e)
process_update(Proxy::Dynflow::Runner::Update.encode_exception('Proxy error', e))
end
|
#runner_dispatcher ⇒ Object
44
45
46
|
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 44
def runner_dispatcher
Proxy::Dynflow::Runner::Dispatcher.instance
end
|