Class: AWS::SimpleWorkflow::DecisionTask
- Inherits:
-
Object
- Object
- AWS::SimpleWorkflow::DecisionTask
- Defined in:
- lib/aws/simple_workflow/decision_task.rb
Overview
Getting Decision Tasks
You can use #poll or #poll_for_single_task on DecisionTaskCollection to grab a decision task:
# get a single task
if task = domain.decision_tasks.poll_for_single_task('task-list')
# make decisions
task.complete!
end
See DecisionTaskCollection for more information on getting and counting decision tasks.
Exploring Event History
Once you have a decision task you can examine the event history. This can give you the information you need to make decisions. The #events and #new_events methods enumerate through all events or events since the last decision.
decision_task.new_events.each do |event|
# inspect the #event_type and #attributes
end
Check out HistoryEvent for more information on working with events.
Making Decisions
Based on the history of events, you should make decisions by calling methods listed below. You can call each method as many times as you wish, until you have completed the decision task.
* {#schedule_activity_task}
* {#request_cancel_activity_task}
* {#complete_workflow_execution}
* {#cancel_workflow_execution}
* {#fail_workflow_execution}
* {#continue_as_new_workflow_execution}
* {#record_marker}
* {#start_timer}
* {#cancel_timer}
* {#signal_external_workflow_execution}
* {#request_cancel_external_workflow_execution}
* {#start_child_workflow_execution}
The decision methods are grouped above by concern.
Completing the Decision Task
Once you have finished adding decisions to the task, you need to complete it. If you called AWS::SimpleWorkflow::DecisionTaskCollection#poll or AWS::SimpleWorkflow::DecisionTaskCollection#poll_for_single_task with a block argument then the decision will be completed automatically at the end of the block.
domain.decision_tasks.poll do |decision_task|
# ...
end #=> the decision task is closed here
If you get a task from AWS::SimpleWorkflow::DecisionTaskCollection#poll_for_single_task without a block, then it is your responsibility to call #complete! on the decision task. If you fail to do this before the task start to close timeout, then a decisionTaskTimedOut event will be added to the workflow execution history.
Instance Attribute Summary collapse
- #domain ⇒ Domain readonly
-
#next_token ⇒ String?
readonly
Returns a value if the results are paginated.
-
#previous_started_event_id ⇒ Integer
readonly
The id of the DecisionTaskStarted event of the previous decision task of this workflow execution that was processed by the decider.
-
#started_event_id ⇒ Integer
readonly
The id of the DecisionTaskStarted event recorded in the history.
-
#task_token ⇒ String
readonly
The decision task identifier.
- #workflow_execution ⇒ WorkflowExecution readonly
- #workflow_type ⇒ WorkflowType readonly
Instance Method Summary collapse
-
#cancel_timer(timer_id) ⇒ nil
Cancels a previously scheduled timer and records a TimerCanceled event in the history.
-
#cancel_workflow_execution(options = {}) ⇒ nil
Closes the workflow execution and records a WorkflowExecutionCanceled event in the history.
- #complete!(options = {}) ⇒ nil
-
#complete_workflow_execution(options = {}) ⇒ nil
Closes the workflow execution and records a WorkflowExecutionCompleted event in the history.
-
#continue_as_new_workflow_execution(options = {}) ⇒ nil
Closes the workflow execution and starts a new workflow execution of the same type using the same workflow id and a unique run Id.
-
#events ⇒ Enumerable
Returns an enumerable collection of all events for the workflow execution.
-
#fail_workflow_execution(options = {}) ⇒ nil
Closes the workflow execution and records a WorkflowExecutionFailed event in the history.
-
#new_events ⇒ Enumerable
Returns an enumerable collection of only the new events for workflow execution (since the last decision).
-
#record_marker(marker_name, options = {}) ⇒ nil
Records a MarkerRecorded event in the history.
-
#request_cancel_activity_task(activity_or_activity_id) ⇒ nil
Attempts to cancel a previously scheduled activity task.
-
#request_cancel_external_workflow_execution(workflow_execution, options = {}) ⇒ nil
Requests that a request be made to cancel the specified external workflow execution and records a RequestCancelExternalWorkflowExecutionRequested event in the history.
-
#responded? ⇒ Boolean
Returns true if #complete! has been called on this decision task.
-
#schedule_activity_task(activity_type, options = {}) ⇒ nil
Schedules an activity task.
-
#signal_external_workflow_execution(workflow_execution, signal_name, options = {}) ⇒ nil
Requests a signal to be delivered to the specified external workflow execution and records a SignalExternalWorkflowExecutionRequested event in the history.
-
#start_child_workflow_execution(workflow_type, options = {}) ⇒ String
Requests that a child workflow execution be started and records a StartChildWorkflowExecutionRequested event in the history.
-
#start_timer(start_to_fire_timeout, options = {}) ⇒ String
Schedules a timer for this workflow execution and records a TimerScheduled event in the history.
Instance Attribute Details
#domain ⇒ Domain (readonly)
127 128 129 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 127 def domain @domain end |
#next_token ⇒ String? (readonly)
Returns a value if the results are paginated. Normally you do not need this value, as #events will enumerate all events, making requests as necessary to get more.
149 150 151 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 149 def next_token @next_token end |
#previous_started_event_id ⇒ Integer (readonly)
Returns The id of the DecisionTaskStarted event of the previous decision task of this workflow execution that was processed by the decider. This can be used to determine the new events in the history new since the last decision task received by the decider.
140 141 142 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 140 def previous_started_event_id @previous_started_event_id end |
#started_event_id ⇒ Integer (readonly)
Returns The id of the DecisionTaskStarted event recorded in the history.
144 145 146 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 144 def started_event_id @started_event_id end |
#task_token ⇒ String (readonly)
Returns The decision task identifier.
124 125 126 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 124 def task_token @task_token end |
#workflow_execution ⇒ WorkflowExecution (readonly)
130 131 132 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 130 def workflow_execution @workflow_execution end |
#workflow_type ⇒ WorkflowType (readonly)
133 134 135 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 133 def workflow_type @workflow_type end |
Instance Method Details
#cancel_timer(timer_id) ⇒ nil
Cancels a previously scheduled timer and records a TimerCanceled event in the history.
465 466 467 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 465 def cancel_timer timer_id add_decision :cancel_timer, { :timer_id => timer_id } end |
#cancel_workflow_execution(options = {}) ⇒ nil
Closes the workflow execution and records a WorkflowExecutionCanceled event in the history.
353 354 355 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 353 def cancel_workflow_execution = {} add_decision :cancel_workflow_execution, end |
#complete!(options = {}) ⇒ nil
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 171 def complete! = {} raise 'already responded' if responded? [:task_token] = task_token [:decisions] = @decisions unless @decisions.empty? client.respond_decision_task_completed() @responded = true nil end |
#complete_workflow_execution(options = {}) ⇒ nil
Closes the workflow execution and records a WorkflowExecutionCompleted event in the history.
324 325 326 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 324 def complete_workflow_execution = {} add_decision :complete_workflow_execution, end |
#continue_as_new_workflow_execution(options = {}) ⇒ nil
Closes the workflow execution and starts a new workflow execution of the same type using the same workflow id and a unique run Id. A WorkflowExecutionContinuedAsNew event is recorded in the history.
410 411 412 413 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 410 def continue_as_new_workflow_execution = {} start_execution_opts() add_decision :continue_as_new_workflow_execution, end |
#events ⇒ Enumerable
Returns an enumerable collection of all events for the workflow execution.
153 154 155 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 153 def events enum_for(:_events) end |
#fail_workflow_execution(options = {}) ⇒ nil
Closes the workflow execution and records a WorkflowExecutionFailed event in the history.
339 340 341 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 339 def fail_workflow_execution = {} add_decision :fail_workflow_execution, end |
#new_events ⇒ Enumerable
Returns an enumerable collection of only the new events for workflow execution (since the last decision).
159 160 161 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 159 def new_events enum_for(:_new_events) end |
#record_marker(marker_name, options = {}) ⇒ nil
Records a MarkerRecorded event in the history. Markers can be used for adding custom information in the history for instance to let deciders know that they do not need to look at the history beyond the marker event.
428 429 430 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 428 def record_marker marker_name, = {} add_decision :record_marker, .merge(:marker_name => marker_name) end |
#request_cancel_activity_task(activity_or_activity_id) ⇒ nil
Attempts to cancel a previously scheduled activity task. If the activity task was scheduled but has not been assigned to a worker, then it will be canceled. If the activity task was already assigned to a worker, then the worker will be informed that cancellation has been requested when recording the activity task heartbeat.
304 305 306 307 308 309 310 311 312 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 304 def request_cancel_activity_task activity_or_activity_id id = activity_or_activity_id.is_a?(ActivityTask) ? activity_or_activity_id.activity_id : activity_or_activity_id add_decision :request_cancel_activity_task, { :activity_id => id } end |
#request_cancel_external_workflow_execution(workflow_execution, options = {}) ⇒ nil
Requests that a request be made to cancel the specified external workflow execution and records a RequestCancelExternalWorkflowExecutionRequested event in the history.
502 503 504 505 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 502 def request_cancel_external_workflow_execution workflow_execution, = {} workflow_execution_opts(, workflow_execution) add_decision :request_cancel_external_workflow_execution, end |
#responded? ⇒ Boolean
Returns true if #complete! has been called on this decision task.
188 189 190 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 188 def responded? !!@responded end |
#schedule_activity_task(activity_type, options = {}) ⇒ nil
This adds a decision to this task that is finalized when you call #complete!.
Schedules an activity task.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 256 def schedule_activity_task activity_type, = {} [:activity_id] ||= UUIDTools::UUID.random_create.to_s [:activity_type] = case activity_type when Hash unless activity_type[:name].is_a?(String) and activity_type[:version].is_a?(String) and activity_type.keys.length == 2 then msg = 'activity_type hash must have :name and :version strings' raise ArgumentError, msg end activity_type when ActivityType { :name => activity_type.name, :version => activity_type.version } else msg = 'expected activity_type to be an ActivityType object or a hash' raise ArgumentError, msg end duration_opts(, :heartbeat_timeout, :schedule_to_close_timeout, :schedule_to_start_timeout, :start_to_close_timeout) if task_list = [:task_list] [:task_list] = { :name => task_list } end add_decision :schedule_activity_task, end |
#signal_external_workflow_execution(workflow_execution, signal_name, options = {}) ⇒ nil
Requests a signal to be delivered to the specified external workflow execution and records a SignalExternalWorkflowExecutionRequested event in the history.
489 490 491 492 493 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 489 def signal_external_workflow_execution workflow_execution, signal_name, = {} workflow_execution_opts(, workflow_execution) [:signal_name] = signal_name add_decision :signal_external_workflow_execution, end |
#start_child_workflow_execution(workflow_type, options = {}) ⇒ String
Requests that a child workflow execution be started and records a StartChildWorkflowExecutionRequested event in the history. The child workflow execution is a separate workflow execution with its own history.
526 527 528 529 530 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 526 def start_child_workflow_execution workflow_type, = {} start_execution_opts(, workflow_type) add_decision :start_child_workflow_execution, [:workflow_id] end |
#start_timer(start_to_fire_timeout, options = {}) ⇒ String
Schedules a timer for this workflow execution and records a TimerScheduled event in the history. This timer will fire after the specified delay and record a TimerFired event.
450 451 452 453 454 455 456 |
# File 'lib/aws/simple_workflow/decision_task.rb', line 450 def start_timer start_to_fire_timeout, = {} [:timer_id] ||= UUIDTools::UUID.random_create.to_s [:start_to_fire_timeout] = start_to_fire_timeout duration_opts(, :start_to_fire_timeout) add_decision :start_timer, [:timer_id] end |