Class: AWS::SimpleWorkflow::ActivityTask

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

Defined Under Namespace

Classes: CancelRequestedError

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(domain, data, options = {}) ⇒ ActivityTask

Returns a new instance of ActivityTask.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

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 specifiy :details that decibe the progress. This might be a percetnage completetion, 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 cancled.

If you need to cleanup or provide addtional details in the cancelation 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