class AWS::Flow::WorkflowDefinition
Represents a workflow definition. Every workflow implementation needs to be a subclass of this class.
Usually there should be no need to instantiate the class manually. Instead, the @execute method is called to start the workflow. You can think of this class as having factory class methods.
Attributes
converter[R]
decision_helper[R]
Public Class Methods
new(instance, workflow_method, signals, get_state_method, converter)
click to toggle source
# File lib/aws/decider/workflow_definition.rb, line 29 def initialize(instance, workflow_method, signals, get_state_method, converter) @instance = instance @workflow_method = workflow_method @get_state_method = get_state_method @signals = signals @converter = converter end
Public Instance Methods
execute(input = nil)
click to toggle source
# File lib/aws/decider/workflow_definition.rb, line 37 def execute(input = nil) #TODO Set up all the converter stuff result = Future.new method_output = Future.new error_handler do |t| t.begin do if input.nil? method_output.set(@instance.send(@workflow_method)) else ruby_input = @converter.load input # Have to have `ruby_input` in order to be able to handle sending # arbitrary arguments correctly, as otherwise it will seem as if # @workflow_method will always have an arity of 1. method_output.set(@instance.send(@workflow_method, *ruby_input)) end end t.rescue(Exception) do |e| # Check if serialized exception violates the 32k limit and truncate it reason, converted_failure = AWS::Flow::Utilities::check_and_truncate_exception(e, @converter) # Wrap the exception that we got into a WorkflowException so that it # can be handled correctly. @failure = WorkflowException.new(reason, converted_failure) end t.ensure do raise @failure if @failure # We are going to have to convert this object into a string to submit it, # and that's where the 32k limit will be enforced, so it's valid to turn # the object to a string and check the size of the result output = @converter.dump method_output.get if output.to_s.size > FlowConstants::DATA_LIMIT raise WorkflowException.new( Utilities.validation_error_string_partial("Workflow"), "" ) end result.set(output) end end return result end
get_workflow_state()
click to toggle source
# File lib/aws/decider/workflow_definition.rb, line 82 def get_workflow_state return nil if @get_state_method.nil? converter = @get_state_method.data_converter || @converter method = @get_state_method.method_name begin result = @instance.send(method) return converter.dump(result) rescue Exception => e raise WorkflowException.new(e.message, converter.dump(e)) end end
signal_received(signal_name, input)
click to toggle source
# File lib/aws/decider/workflow_definition.rb, line 96 def signal_received(signal_name, input) method_pair = @signals[signal_name] raise "No such signal for #{signal_name}" unless method_pair converter = method_pair.data_converter method_name = method_pair.method_name error_handler do |t| parameters = nil t.begin do if input.class <= NoInput @instance.send(method_name) else parameters = converter.load input @instance.send(method_name, *parameters) end end t.rescue(Exception) do |e| WorkflowException.new("Got an error while sending #{method_name} with parameters #{parameters}", converter.dump(e)) end end end