Class: AWS::Flow::Templates::RootTemplate

Inherits:
TemplateBase show all
Defined in:
aws-flow-ruby/aws-flow/lib/aws/templates/base.rb

Overview

Root template is the top level template that is sent to a workflow to run. It contains a step (which is another template) that it passes the input and the context to. It also contains a result_step that it uses to report the result of the workflow.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RootTemplate) initialize(step, result_step)

Returns a new instance of RootTemplate



32
33
34
35
# File 'aws-flow-ruby/aws-flow/lib/aws/templates/base.rb', line 32

def initialize(step, result_step)
  @step = step
  @result_step = result_step
end

Instance Attribute Details

- (Object) input (readonly)

Returns the value of attribute input



29
30
31
# File 'aws-flow-ruby/aws-flow/lib/aws/templates/base.rb', line 29

def input
  @input
end

- (Object) result_step

Returns the value of attribute result_step



30
31
32
# File 'aws-flow-ruby/aws-flow/lib/aws/templates/base.rb', line 30

def result_step
  @result_step
end

- (Object) step (readonly)

Returns the value of attribute step



29
30
31
# File 'aws-flow-ruby/aws-flow/lib/aws/templates/base.rb', line 29

def step
  @step
end

Instance Method Details

- (Object) run(input, context)

Calls the run method on the step (top level template). Manages overall error handling and reporting of results for the workflow



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'aws-flow-ruby/aws-flow/lib/aws/templates/base.rb', line 39

def run(input, context)
  result = nil
  failure = nil
  begin
    result = @step.run(input, context)
  rescue Exception => e
    failure = e
  ensure
    if failure
      # If there is a result_step, pass the failure as an input to it.
      @result_step.run({failure: failure}, context) if @result_step
      # Now fail the workflow
      raise e
    else
      # Pass the result as an input to the result_step
      @result_step.run(result, context) if @result_step
      # Complete the workflow by returning the result
      result
    end
  end
end