Class: AWS::Flow::ActivityDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/decider/activity_definition.rb

Overview

Defines an executable activity.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, activity_method, registration_options, execution_options, converter) ⇒ ActivityDefinition

Creates a new ActivityDefinition instance.

Parameters:

  • instance (Object)
  • activity_method (Symbol)

    The method to run when #execute is called.

  • registration_options (Hash)
  • execution_options (Hash)

    The AWS::Flow::ActivityOptions for this activity.

  • converter (Object)


41
42
43
44
45
46
47
# File 'lib/aws/decider/activity_definition.rb', line 41

def initialize(instance, activity_method, registration_options, execution_options, converter)
  @instance = instance
  @activity_method = activity_method
  @registration_options = registration_options
  @execution_options = execution_options
  @converter = converter
end

Instance Attribute Details

#execution_optionsObject

Returns the value of attribute execution_options.



25
26
27
# File 'lib/aws/decider/activity_definition.rb', line 25

def execution_options
  @execution_options
end

Instance Method Details

#execute(input, context) ⇒ Object

Executes the activity.

Parameters:

  • input (Object)

    Additional input for the activity execution.

  • context (ActivityExecutionContext)

    The context for the activity execution.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/aws/decider/activity_definition.rb', line 57

def execute(input, context)
  begin
    @instance._activity_execution_context = context
    # Since we encode all the inputs in some converter, and these inputs
    # are not "true" Ruby objects yet, there is no way for that input to
    # be an instance of the NilClass(the only thing that responds true to
    # .nil?) and thus we can be assured that if input.nil?, then the
    # method had no input.
    if input.nil?
      result = @instance.send(@activity_method)
    else
      ruby_input = @converter.load input
      result = @instance.send(@activity_method, *ruby_input)
    end
  rescue Exception => e
    #TODO we need the proper error handling here
    raise e if e.is_a? CancellationException
    raise ActivityFailureException.new(e.message, @converter.dump(e))
  ensure
    @instance._activity_execution_context = nil
  end
  converted_result = @converter.dump(result)
  # 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
  if converted_result.to_s.size > 32768
    return @converter.dump("The result was too large, so we could not serialize it correctly. You can find the full result in the ActivityTaskPoller logs."), result, true
  end
  return converted_result, result, false
end