class AWS::Flow::Templates::ActivityTemplate

This template represents an Activity in SWF. It holds the name and scheduling options for the activity

Attributes

name[R]
options[R]

Public Class Methods

new(name, opts = {}) click to toggle source
# File lib/aws/templates/activity.rb, line 10
def initialize(name, opts = {})
  options = opts.dup
  # Split the name into prefix name and activity method
  prefix_name, @name = name.split(".")

  # Raise if we don't have a fully qualified name for the activity
  raise ArgumentError, "Activity name should be fully qualified: "\
    "<prefix_name>.<activity_method>" unless @name

  # Get all the property keys from the ActivityOptions class
  keys = ActivityOptions.held_properties.push(:exponential_retry)

  # Only select the options that are needed
  options.select!{ |x| keys.include?(x) }

  # Merge in default values for the activity in case they are not passed
  # by the user
  options = {
    version: FlowConstants.defaults[:version],
    prefix_name: "#{prefix_name}",
    data_converter:  FlowConstants.defaults[:data_converter],
    exponential_retry: FlowConstants.defaults[:retry_policy]
  }.merge(options)

  @options = options
end

Public Instance Methods

run(input, context) click to toggle source

Uses the ActivityClient given in the context (workflow class) passed in by the calling template to schedule this activity

# File lib/aws/templates/activity.rb, line 39
def run(input, context)
  # Get a duplicate of the options hash so as not to change what's
  # stored in this object
  options = @options.dup
  # If a :tasklist key is passed as input to this template, then schedule
  # this activity on that tasklist
  if input.is_a?(Hash) && input[:task_list]
    options.merge!(task_list: input[:task_list])
  end
  # Schedule the activity using the ActivityClient in the context
  context.act_client.send(@name, input) { options }
end