Module: AWS::Flow::Activities

Extended by:
Utilities::UpwardLookups
Included in:
Activity, Templates::FlowDefaultResultActivityRuby
Defined in:
lib/aws/decider/activity.rb

Overview

Methods and constants related to activities.

Defined Under Namespace

Modules: InstanceMethods

Instance Attribute Summary collapse

Attributes included from Utilities::UpwardLookups

#precursors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities::UpwardLookups

held_properties, properties, property

Instance Attribute Details

#activitiesObject

Gets the list of AWS::Flow::ActivityType objects that were created by the #activity method.



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/aws/decider/activity.rb', line 361

module Activities
  @precursors ||= []
  attr_accessor :activity_client, :activities
  def self.extended(base)
    base.send :include, InstanceMethods
  end
  module InstanceMethods
    # Sets the {ActivityExecutionContext} instance for the activity task.
    attr_writer :_activity_execution_context

    # Gets the activity execution context for the activity task. Raises an `IllegalStateException` if the activity
    # has no context.
    #
    # @return [ActivityExecutionContext] The execution context for this activity.
    #
    def activity_execution_context
      raise IllegalStateException.new("No activity execution context") unless @_activity_execution_context
      @_activity_execution_context
    end

    # Records a heartbeat for the activity, indicating to Amazon SWF that the activity is still making progress.
    #
    # @param [String] details
    #   If specified, contains details about the progress of the activity task. Up to 2048
    #   characters can be provided.
    #
    def record_activity_heartbeat(details)
      @_activity_execution_context.record_activity_heartbeat(details)
    end
  end

  # @api private
  extend Utilities::UpwardLookups

  # @api private
  def look_upwards(variable)
    precursors = self.ancestors.dup
    precursors.delete(self)
    results = precursors.map { |x| x.send(variable) if x.methods.map(&:to_sym).include? variable }.compact.flatten.uniq
  end
  property(:activities, [])

  # @api private
  def _options; @activities; end

  # Defines one or more activities with {ActivityRegistrationOptions} provided in the
  # supplied block.
  #
  # @param [Array] activity_names
  #   The names of the activities to define. These names will be used to
  #   create {ActivityType} objects, one per name.
  #
  #   Each activity type is named as *prefix.activity_name*, where the
  #   *prefix* is specified in the options block, and each *activity_name*
  #   comes from the list passed to this parameter.
  #
  # @param [Hash] block
  #   {ActivityRegistrationOptions} to use on the defined activities.
  #
  #   The following options are *required* when registering an activity:
  #
  #   * `version` - The version of the activity type.
  #   * `task_list` - The task list used to poll for activity tasks.
  #
  # @example Defining an activity
  #   new_activity_class = Class.new(MyActivity) do
  #     extend Activities
  #
  #     activity :activity1 do
  #     {
  #       :default_task_heartbeat_timeout => "3600",
  #       :default_task_list => task_list,
  #       :default_task_schedule_to_close_timeout => "20",
  #       :default_task_schedule_to_start_timeout => "20",
  #       :default_task_start_to_close_timeout => "20",
  #       :default_task_priority => "0",
  #       :version => "1",
  #       :prefix_name => "ExampleActivity"
  #     }
  #     end
  #
  #     def activity1
  #       puts "Hello!"
  #     end
  #   end
  def activity(*activity_names, &block)
    options = Utilities::interpret_block_for_options(ActivityRegistrationOptions, block)
    activity_names.each do |activity_name|
      prefix_name = options.prefix_name || self.to_s
      activity_type = ActivityType.new(prefix_name + "." + activity_name.to_s, options.version, options)
      @activities ||= []
      @activities << activity_type
    end
  end
end

#activity_clientObject

Gets the AWS::Flow::ActivityClient contained by the class.



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/aws/decider/activity.rb', line 361

module Activities
  @precursors ||= []
  attr_accessor :activity_client, :activities
  def self.extended(base)
    base.send :include, InstanceMethods
  end
  module InstanceMethods
    # Sets the {ActivityExecutionContext} instance for the activity task.
    attr_writer :_activity_execution_context

    # Gets the activity execution context for the activity task. Raises an `IllegalStateException` if the activity
    # has no context.
    #
    # @return [ActivityExecutionContext] The execution context for this activity.
    #
    def activity_execution_context
      raise IllegalStateException.new("No activity execution context") unless @_activity_execution_context
      @_activity_execution_context
    end

    # Records a heartbeat for the activity, indicating to Amazon SWF that the activity is still making progress.
    #
    # @param [String] details
    #   If specified, contains details about the progress of the activity task. Up to 2048
    #   characters can be provided.
    #
    def record_activity_heartbeat(details)
      @_activity_execution_context.record_activity_heartbeat(details)
    end
  end

  # @api private
  extend Utilities::UpwardLookups

  # @api private
  def look_upwards(variable)
    precursors = self.ancestors.dup
    precursors.delete(self)
    results = precursors.map { |x| x.send(variable) if x.methods.map(&:to_sym).include? variable }.compact.flatten.uniq
  end
  property(:activities, [])

  # @api private
  def _options; @activities; end

  # Defines one or more activities with {ActivityRegistrationOptions} provided in the
  # supplied block.
  #
  # @param [Array] activity_names
  #   The names of the activities to define. These names will be used to
  #   create {ActivityType} objects, one per name.
  #
  #   Each activity type is named as *prefix.activity_name*, where the
  #   *prefix* is specified in the options block, and each *activity_name*
  #   comes from the list passed to this parameter.
  #
  # @param [Hash] block
  #   {ActivityRegistrationOptions} to use on the defined activities.
  #
  #   The following options are *required* when registering an activity:
  #
  #   * `version` - The version of the activity type.
  #   * `task_list` - The task list used to poll for activity tasks.
  #
  # @example Defining an activity
  #   new_activity_class = Class.new(MyActivity) do
  #     extend Activities
  #
  #     activity :activity1 do
  #     {
  #       :default_task_heartbeat_timeout => "3600",
  #       :default_task_list => task_list,
  #       :default_task_schedule_to_close_timeout => "20",
  #       :default_task_schedule_to_start_timeout => "20",
  #       :default_task_start_to_close_timeout => "20",
  #       :default_task_priority => "0",
  #       :version => "1",
  #       :prefix_name => "ExampleActivity"
  #     }
  #     end
  #
  #     def activity1
  #       puts "Hello!"
  #     end
  #   end
  def activity(*activity_names, &block)
    options = Utilities::interpret_block_for_options(ActivityRegistrationOptions, block)
    activity_names.each do |activity_name|
      prefix_name = options.prefix_name || self.to_s
      activity_type = ActivityType.new(prefix_name + "." + activity_name.to_s, options.version, options)
      @activities ||= []
      @activities << activity_type
    end
  end
end

Class Method Details

.extended(base) ⇒ Object



364
365
366
# File 'lib/aws/decider/activity.rb', line 364

def self.extended(base)
  base.send :include, InstanceMethods
end

Instance Method Details

#_optionsObject

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.



404
# File 'lib/aws/decider/activity.rb', line 404

def _options; @activities; end

#activity(*activity_names, &block) ⇒ Object

Defines one or more activities with AWS::Flow::ActivityRegistrationOptions provided in the supplied block.

Examples:

Defining an activity

new_activity_class = Class.new(MyActivity) do
  extend Activities

  activity :activity1 do
  {
    :default_task_heartbeat_timeout => "3600",
    :default_task_list => task_list,
    :default_task_schedule_to_close_timeout => "20",
    :default_task_schedule_to_start_timeout => "20",
    :default_task_start_to_close_timeout => "20",
    :default_task_priority => "0",
    :version => "1",
    :prefix_name => "ExampleActivity"
  }
  end

  def activity1
    puts "Hello!"
  end
end

Parameters:

  • activity_names (Array)

    The names of the activities to define. These names will be used to create AWS::Flow::ActivityType objects, one per name.

    Each activity type is named as prefix.activity_name, where the prefix is specified in the options block, and each activity_name comes from the list passed to this parameter.

  • block (Hash)

    AWS::Flow::ActivityRegistrationOptions to use on the defined activities.

    The following options are required when registering an activity:

    • ‘version` - The version of the activity type.

    • ‘task_list` - The task list used to poll for activity tasks.



446
447
448
449
450
451
452
453
454
# File 'lib/aws/decider/activity.rb', line 446

def activity(*activity_names, &block)
  options = Utilities::interpret_block_for_options(ActivityRegistrationOptions, block)
  activity_names.each do |activity_name|
    prefix_name = options.prefix_name || self.to_s
    activity_type = ActivityType.new(prefix_name + "." + activity_name.to_s, options.version, options)
    @activities ||= []
    @activities << activity_type
  end
end

#look_upwards(variable) ⇒ 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.



396
397
398
399
400
# File 'lib/aws/decider/activity.rb', line 396

def look_upwards(variable)
  precursors = self.ancestors.dup
  precursors.delete(self)
  results = precursors.map { |x| x.send(variable) if x.methods.map(&:to_sym).include? variable }.compact.flatten.uniq
end