Class: AWS::SimpleWorkflow::ActivityTask

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/simple_workflow/activity_task.rb

Defined Under Namespace

Classes: CancelRequestedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#activity_idString (readonly)

Returns The unique identifier of this task.

Returns:

  • (String)

    The unique identifier of this task.



50
51
52
# File 'lib/aws/simple_workflow/activity_task.rb', line 50

def activity_id
  @activity_id
end

#activity_typeActivityType (readonly)

Returns:



64
65
66
# File 'lib/aws/simple_workflow/activity_task.rb', line 64

def activity_type
  @activity_type
end

#domainDomain (readonly)

Returns The domain this task was scheduled in.

Returns:

  • (Domain)

    The domain this task was scheduled in.



53
54
55
# File 'lib/aws/simple_workflow/activity_task.rb', line 53

def domain
  @domain
end

#inputString? (readonly)

Returns The input provided when the activity task was scheduled.

Returns:

  • (String, nil)

    The input provided when the activity task was scheduled.



61
62
63
# File 'lib/aws/simple_workflow/activity_task.rb', line 61

def input
  @input
end

#started_event_idInteger (readonly)

Returns The id of the ActivityTaskStarted event recorded in the history.

Returns:

  • (Integer)

    The id of the ActivityTaskStarted event recorded in the history.



57
58
59
# File 'lib/aws/simple_workflow/activity_task.rb', line 57

def started_event_id
  @started_event_id
end

#task_tokenString (readonly)

Returns The opaque string used as a handle on the task.

Returns:

  • (String)

    The opaque string used as a handle on the task.



47
48
49
# File 'lib/aws/simple_workflow/activity_task.rb', line 47

def task_token
  @task_token
end

#workflow_executionWorkflowExecution (readonly)

Returns:



67
68
69
# File 'lib/aws/simple_workflow/activity_task.rb', line 67

def workflow_execution
  @workflow_execution
end

Instance Method Details

#cancel!(options = {}) ⇒ nil

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :details (String) — default: nil

Returns:

  • (nil)


142
143
144
# File 'lib/aws/simple_workflow/activity_task.rb', line 142

def cancel! options = {}
  respond :canceled, options
end

#complete!(options = {}) ⇒ nil

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :result (String) — default: nil

Returns:

  • (nil)


132
133
134
# File 'lib/aws/simple_workflow/activity_task.rb', line 132

def complete! options = {}
  respond :completed, options
end

#fail!(options = {}) ⇒ nil

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :details (String) — default: nil
  • :reason (String) — default: nil

Returns:

  • (nil)


154
155
156
# File 'lib/aws/simple_workflow/activity_task.rb', line 154

def fail! options = {}
  respond :failed, options
end

#record_heartbeat!(options = {}) ⇒ Object

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 AWS::SimpleWorkflow::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

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :details (String) — default: nil

    If specified, contains details about the progress of the task.

Raises:



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/aws/simple_workflow/activity_task.rb', line 112

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?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/aws/simple_workflow/activity_task.rb', line 158

def responded?
  !!@responded
end