Class: Proxy::Dynflow::Action::Runner

Inherits:
Shareable
  • Object
show all
Includes:
Dynflow::Action::Cancellable, WithExternalPolling
Defined in:
lib/smart_proxy_dynflow/action/runner.rb

Direct Known Subclasses

BatchRunner, OutputCollector

Constant Summary

Constants included from WithExternalPolling

WithExternalPolling::Poll

Instance Method Summary collapse

Methods inherited from Shareable

#plan

Instance Method Details

#failed_run?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 84

def failed_run?
  output[:exit_status] != 0
end

#finalizeObject



32
33
34
35
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 32

def finalize
  # To mark the task as a whole as failed
  error! 'Script execution failed' if on_proxy? && failed_run?
end

#finish_run(update) ⇒ Object



60
61
62
63
64
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 60

def finish_run(update)
  output[:exit_status] = update.exit_status
  output[:result] = output_result
  drop_output_chunks!
end

#init_runObject



45
46
47
48
49
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 45

def init_run
  output[:result] = []
  output[:runner_id] = runner_dispatcher.start(suspended_action, initiate_runner)
  suspend
end

#initiate_runnerObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 41

def initiate_runner
  raise NotImplementedError
end

#kill_runObject



55
56
57
58
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 55

def kill_run
  runner_dispatcher.kill(output[:runner_id])
  suspend
end

#output_resultObject



88
89
90
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 88

def output_result
  (stored_output_chunks + (@pending_output_chunks || [])).map { |c| c[:chunk] }.reduce([], &:concat)
end

#pollObject



80
81
82
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 80

def poll
  runner_dispatcher.refresh_output(output[:runner_id])
end

#process_external_event(event) ⇒ Object



66
67
68
69
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 66

def process_external_event(event)
  runner_dispatcher.external_event(output[:runner_id], event)
  suspend
end

#process_update(update) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 71

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_selfObject



37
38
39
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 37

def rescue_strategy_for_self
  ::Dynflow::Action::Rescue::Fail
end

#run(event = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 11

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
  when ::Proxy::Dynflow::Action::WithExternalPolling::Poll
    poll
    suspend
  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_dispatcherObject



51
52
53
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 51

def runner_dispatcher
  Proxy::Dynflow::Runner::Dispatcher.instance
end