Class: AWS::Flow::Templates::ActivityTemplate Private

Inherits:
TemplateBase
  • Object
show all
Defined in:
lib/aws/templates/activity.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Direct Known Subclasses

ResultActivityTemplate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ ActivityTemplate

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ActivityTemplate.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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

Instance Attribute Details

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/aws/templates/activity.rb', line 8

def name
  @name
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/aws/templates/activity.rb', line 8

def options
  @options
end

Instance Method Details

#run(input, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



39
40
41
42
43
44
45
46
47
48
49
50
# 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