class AWS::SimpleWorkflow::ActivityTask

Attributes

activity_id[R]

@return [String] The unique identifier of this task.

activity_type[R]

@return [ActivityType]

domain[R]

@return [Domain] The domain this task was scheduled in.

input[R]

@return [String,nil] The input provided when the activity task was

scheduled.
started_event_id[R]

@return [Integer]

The id of the {ActivityTaskStarted} event recorded in the history.
task_token[R]

@return [String] The opaque string used as a handle on the task.

workflow_execution[R]

@return [WorkflowExecution]

Public Class Methods

new(domain, data, options = {}) click to toggle source

@api private

Calls superclass method AWS::Core::Model.new
# File lib/aws/simple_workflow/activity_task.rb, line 25
def initialize domain, data, options = {}

  @domain = domain

  @task_token = data['taskToken']
  @activity_id = data['activityId']
  @started_event_id = data['startedEventId']
  @input = data['input']

  name = data['activityType']['name']
  version = data['activityType']['version']
  @activity_type = domain.activity_types[name,version]

  workflow_id = data['workflowExecution']['workflowId']
  run_id = data['workflowExecution']['runId']
  @workflow_execution = domain.workflow_executions[workflow_id,run_id]

  super

end

Public Instance Methods

cancel!(options = {}) click to toggle source

@param [Hash] options

@option options [String] :details (nil)

@return [nil]

# File lib/aws/simple_workflow/activity_task.rb, line 135
def cancel! options = {}
  respond :canceled, options
end
complete!(options = {}) click to toggle source

@param [Hash] options

@option options [String] :result (nil)

@return [nil]

# File lib/aws/simple_workflow/activity_task.rb, line 125
def complete! options = {}
  respond :completed, options
end
fail!(options = {}) click to toggle source

@param [Hash] options

@option options [String] :details (nil)

@option options [String] :reason (nil)

@return [nil]

# File lib/aws/simple_workflow/activity_task.rb, line 147
def fail! options = {}
  respond :failed, options
end
record_heartbeat!(options = {}) click to toggle source

Reports to the service that the activity task is progressing.

You can optionally specify `:details` that describe the progress. This might be a percentage competition, step number, etc.

activity_task.record_heartbeat! :details => '.75' # 75% complete

If the activity task has been canceled since it was received or since the last recorded heartbeat, this method will raise a CancelRequestedError.

If you are processing the activity task inside a block passed to one of the polling methods in {ActivityTaskCollection} then untrapped CancelRequestedErrors are caught and responded to automatically.

domain.activity_tasks.poll('task-list') do |task|
  task.record_heartbeat! # raises CancelRequestedError
end # traps the error and responds activity task canceled.

If you need to cleanup or provide additional details in the cancellation response, you can trap the error and respond manually.

domain.activity_tasks.poll('task-list') do |task|
  task.record_heartbeat! # raises CancelRequestedError
rescue CancelRequestedError => e
   # cleanup
   task.respond_canceled! :details => '...'
end

@param [Hash] options

@option options [String] :details (nil)

If specified, contains details about the progress of the task.
# File lib/aws/simple_workflow/activity_task.rb, line 105
def record_heartbeat! options = {}

  client_opts = {}
  client_opts[:task_token] = task_token
  client_opts[:details] = options[:details] if options[:details]

  response = client.record_activity_task_heartbeat(client_opts)

  raise CancelRequestedError if response.data['cancelRequested']

  nil

end
responded?() click to toggle source
# File lib/aws/simple_workflow/activity_task.rb, line 151
def responded?
  !!@responded
end

Protected Instance Methods

respond(status, options) click to toggle source

Responds to one of the `respond_activity_task_` methods with a set of options. This method is called when any of the {#complete!}, {#cancel!}, or {#fail!} methods is invoked.

@note Only one response can be logged per `ActivityTask` instance; If this task has already logged a response,

`respond` will raise an exception.

@param [String] status

The status of the response: "canceled", "completed", or "failed".

@param [Hash] options

Options to provide to the respond_activity_task function that will be called.
# File lib/aws/simple_workflow/activity_task.rb, line 168
def respond status, options
  raise "already responded" if responded?
  @responded = status
  options[:task_token] = task_token
  client.send("respond_activity_task_#{status}", options)
  nil
end