Class: Proxy::Dynflow::Runner::Parent

Inherits:
Base
  • Object
show all
Defined in:
lib/smart_proxy_dynflow/runner/parent.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #logger

Instance Method Summary collapse

Methods inherited from Base

#close, #external_event, #kill, #new_update, #no_update, #publish_exception, #publish_exit_status, #refresh, #run_refresh, #run_refresh_output, #start, #timeout, #timeout_interval

Constructor Details

#initialize(targets = {}, suspended_action: nil, id: nil) ⇒ Parent

targets = { identifier => { :execution_plan_id => “…”, :run_step_id => id,

:input => { ... } }


8
9
10
11
12
# File 'lib/smart_proxy_dynflow/runner/parent.rb', line 8

def initialize(targets = {}, suspended_action: nil, id: nil)
  @targets = targets
  @exit_statuses = {}
  super suspended_action: suspended_action, id: id
end

Instance Method Details

#broadcast_data(data, type) ⇒ Object



38
39
40
# File 'lib/smart_proxy_dynflow/runner/parent.rb', line 38

def broadcast_data(data, type)
  @outputs.each_value { |output| output.add_output(data, type) }
end

#dispatch_exception(context, exception) ⇒ Object



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

def dispatch_exception(context, exception)
  @outputs.each_value { |output| output.add_exception(context, exception) }
end

#generate_updatesObject



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

def generate_updates
  base = {}
  base[@suspended_action] = Runner::Update.new(Proxy::Dynflow::ContinuousOutput.new, @exit_status) if @exit_status
  # Operate on all hosts if the main process ended or only on hosts for which we have updates
  @outputs.reject { |_, output| @exit_status.nil? && output.empty? }
          .reduce(base) do |acc, (identifier, output)|
            @outputs[identifier] = Proxy::Dynflow::ContinuousOutput.new # Create a new ContinuousOutput for next round of updates
            exit_status = @exit_statuses[identifier] || @exit_status if @exit_status
            acc.merge(host_action(identifier) => Runner::Update.new(output, exit_status))
          end
end

#host_action(identifier) ⇒ Object



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

def host_action(identifier)
  options = @targets[identifier].slice('execution_plan_id', 'run_step_id')
                                .merge(:world => Proxy::Dynflow::Core.world)
  Dynflow::Action::Suspended.new OpenStruct.new(options)
end

#initialize_continuous_outputsObject



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

def initialize_continuous_outputs
  @outputs = @targets.keys.reduce({}) do |acc, target|
    acc.merge(target => Proxy::Dynflow::ContinuousOutput.new)
  end
end

#publish_data(_data, _type) ⇒ Object



42
43
44
# File 'lib/smart_proxy_dynflow/runner/parent.rb', line 42

def publish_data(_data, _type)
  true
end

#publish_data_for(identifier, data, type) ⇒ Object



46
47
48
# File 'lib/smart_proxy_dynflow/runner/parent.rb', line 46

def publish_data_for(identifier, data, type)
  @outputs[identifier].add_output(data, type)
end

#publish_exit_status_for(identifier, exit_status) ⇒ Object



54
55
56
# File 'lib/smart_proxy_dynflow/runner/parent.rb', line 54

def publish_exit_status_for(identifier, exit_status)
  @exit_statuses[identifier] = exit_status
end