Class: ManageIQ::Floe::Workflow::States::Task

Inherits:
ManageIQ::Floe::Workflow::State show all
Defined in:
lib/manageiq/floe/workflow/states/task.rb

Instance Attribute Summary collapse

Attributes inherited from ManageIQ::Floe::Workflow::State

#comment, #name, #payload, #type, #workflow

Instance Method Summary collapse

Methods inherited from ManageIQ::Floe::Workflow::State

build!, #context, #end?, #to_dot, #to_dot_transitions

Methods included from Logging

included, #logger

Constructor Details

#initialize(workflow, name, payload) ⇒ Task

Returns a new instance of Task.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/manageiq/floe/workflow/states/task.rb', line 12

def initialize(workflow, name, payload)
  super

  @heartbeat_seconds = payload["HeartbeatSeconds"]
  @next              = payload["Next"]
  @resource          = payload["Resource"]
  @timeout_seconds   = payload["TimeoutSeconds"]
  @retry             = payload["Retry"].to_a.map { |retrier| Retrier.new(retrier) }
  @catch             = payload["Catch"].to_a.map { |catcher| Catcher.new(catcher) }
  @input_path        = Path.new(payload.fetch("InputPath", "$"))
  @output_path       = Path.new(payload.fetch("OutputPath", "$"))
  @result_path       = ReferencePath.new(payload.fetch("ResultPath", "$"))
  @parameters        = PayloadTemplate.new(payload["Parameters"])     if payload["Parameters"]
  @result_selector   = PayloadTemplate.new(payload["ResultSelector"]) if payload["ResultSelector"]
  @credentials       = PayloadTemplate.new(payload["Credentials"])    if payload["Credentials"]
end

Instance Attribute Details

#catchObject (readonly)

Returns the value of attribute catch.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def catch
  @catch
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def credentials
  @credentials
end

#endObject (readonly)

Returns the value of attribute end.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def end
  @end
end

#heartbeat_secondsObject (readonly)

Returns the value of attribute heartbeat_seconds.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def heartbeat_seconds
  @heartbeat_seconds
end

#input_pathObject (readonly)

Returns the value of attribute input_path.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def input_path
  @input_path
end

#nextObject (readonly)

Returns the value of attribute next.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def next
  @next
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def output_path
  @output_path
end

#parametersObject (readonly)

Returns the value of attribute parameters.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def parameters
  @parameters
end

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def resource
  @resource
end

#result_pathObject (readonly)

Returns the value of attribute result_path.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def result_path
  @result_path
end

#result_selectorObject (readonly)

Returns the value of attribute result_selector.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def result_selector
  @result_selector
end

#retryObject (readonly)

Returns the value of attribute retry.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def retry
  @retry
end

#timeout_secondsObject (readonly)

Returns the value of attribute timeout_seconds.



8
9
10
# File 'lib/manageiq/floe/workflow/states/task.rb', line 8

def timeout_seconds
  @timeout_seconds
end

Instance Method Details

#run!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/manageiq/floe/workflow/states/task.rb', line 29

def run!(*)
  super do |input|
    input = parameters.value(context, input) if parameters

    runner = ManageIQ::Floe::Workflow::Runner.for_resource(resource)
    _exit_status, results = runner.run!(resource, input, credentials&.value({}, workflow.credentials))

    output = input
    process_output!(output, results)
  rescue => err
    retrier = self.retry.detect { |r| (r.error_equals & [err.to_s, "States.ALL"]).any? }
    retry if retry!(retrier)

    catcher = self.catch.detect { |c| (c.error_equals & [err.to_s, "States.ALL"]).any? }
    raise if catcher.nil?

    [output, workflow.states_by_name[catcher.next]]
  end
end