Class AWS::SimpleWorkflow::DecisionTask
In: lib/aws/simple_workflow/decision_task.rb
Parent: Object

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 deicision methods are grouped above by concern.

Completing the Decision Task

Once you have finished adding deicions to the task, you need to complete it. If you called {DecisionTaskCollection#poll} or {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 {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.

Methods

Included Modules

Core::Model OptionFormatters

Attributes

domain  [R]  @return [Domain]
next_token  [R]  @return [String,nil] 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.
previous_started_event_id  [R]  @return [Integer] 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.
started_event_id  [R]  @return [Integer] The id of the DecisionTaskStarted event recorded
  in the history.
task_token  [R]  @return [String] The decision task identifier.
workflow_execution  [R]  @return [WorkflowExecution]
workflow_type  [R]  @return [WorkflowType]

Public Class methods

Public Instance methods

Cancels a previously scheduled timer and records a TimerCanceled event in the history.

@param [String] timer_id The id of the timer to cancel.

@return [nil]

Closes the workflow execution and records a WorkflowExecutionCanceled event in the history.

@param [Hash] options

@option options [String] :details (nil) Optional details of the

  cancellation.

@return [nil]

@param [Hash] options

@option options [String] :execution_context (nil) A user-defined

  context to add to the workflow execution.  You can fetch this
  later with {WorkflowExecution#latest_execution_context}.

@return [nil]

Closes the workflow execution and records a WorkflowExecutionCompleted event in the history.

@param [Hash] options

@option options [String] :result (nil) The results of the workflow

  execution.

@return [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.

@option options [String] :input (nil)

  The input for the workflow execution. This is a free form string
  which should be meaningful to the workflow you are starting.
  This input is made available to the new workflow execution in the
  WorkflowExecutionStarted history event.

@option options [Array<string>] :tag_list ([])

  A list of tags (strings) to associate with the workflow execution.
  You can specify a maximum of 5 tags.

@option options [Symbol] :child_policy (nil)

  Specifies the policy to use for the child workflow executions of
  this workflow execution if it is terminated explicitly or due to
  an expired timeout. This policy overrides the default child policy
  specified when registering the workflow type.  The supported child
  policies are:

  * +:terminate+ - the child executions will be terminated.

  * +:request_cancel+ - a request to cancel will be attempted for each
    child execution by recording a WorkflowExecutionCancelRequested
    event in its history. It is up to the decider to take appropriate
    actions when it receives an execution history with this event.

  * +:abandon+ - no action will be taken. The child executions will
    continue to run.

@option options [Integer,:none] :execution_start_to_close_timeout (nil)

  The total duration for this workflow execution.  This overrides
  the default specified when registering the workflow type.

  The value should be a number of seconds (integer) or the symbol
  +:none+ (implying no timeout).

@option options [String] :task_list (nil)

  The task list to use for the decision tasks generated for this
  workflow execution. This overrides the default task list specified
  when registering the workflow type.

@option options [Integer,:none] :task_start_to_close_timeout (nil)

  Specifies the maximum duration of decision tasks for this
  workflow execution. This parameter overrides the default
  specified when the workflow type was registered.

  The value should be a number of seconds (integer) or the symbol
  +:none+ (implying no timeout).

@return [nil]

@return [Enumerable] Returns an enumerable collection of all events

  for the workflow execution.

Closes the workflow execution and records a WorkflowExecutionFailed event in the history.

@param [Hash] options

@option options [String] :reason (nil) Reason for the failure.

@option options [String] :details (nil) Optional details of the failure.

@return [nil]

@return [Enumerable] Returns an enumerable collection of only the

  new events for workflow execution (since the last decision).

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.

@param [String] marker_name The name of the marker.

@param [Hash] options

@option options [String] :details (nil) Optional details of the marker.

@return [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.

@param [ActivityTask,String] activity_or_activity_id An {ActivityTask}

  object or the activity_id of an activity task to request
  cancellation for.

@return [nil]

Requests that a request be made to cancel the specified external workflow execution and records a RequestCancelExternalWorkflowExecutionRequested event in the history.

@return [nil]

@return [Boolean] Returns true if {complete!} has been called on

  this decision task.

Schedules an activity task.

@note This adds a decision to this task that is finalized when you

  call {#complete!}.

@param [ActivityType,Hash] activity_type The type of activity

  to schedule.  +activity_type+ must be an {ActivityType} object
  or a hash with +:name+ and +:version+.

@param [Hash] options

@option options [String] :control (nil) Optional data attached to

  the event that can be used by the decider in subsequent workflow
  tasks. This data is not sent to the activity.

@option options [Integer,:none] :heartbeat_timeout (nil)

  The maximum time before which a worker processing a task
  of this type must report progress.  If the timeout is exceeded,
  the activity task is automatically timed out. If the worker
  subsequently attempts to record a heartbeat or returns a
  result, it will be ignored. This default can be overridden when
  scheduling an activity task.

  The value should be a number of seconds (integer) or the symbol
  +:none+ (implying no timeout).

@option options [String] :input (nil) Input provided to the

  activity task.

@option options [Integer,:none] :schedule_to_close_timeout (nil)

  The maximum duration that a task of this activity type
  can wait before being assigned to a worker.

  A schedule-to-close timeout for this activity task must be
  specified either as a default for the activity type or through
  this option. If neither this field is set nor a default was
  specified at registration time then a fault will be returned.

  The value should be a number of seconds (integer) or the symbol
  +:none+ (implying no timeout).

@option options [Integer,:none] :schedule_to_start_timeout (nil)

  The maximum duration that a task of this activity type
  can wait before being assigned to a worker.  This overrides the
  default timeout specified when registering the activity type.

  The value should be a number of seconds (integer) or the symbol
  +:none+ (implying no timeout).

@option options [Integer,:none] :start_to_close_timeout (nil)

  The maximum duration that a worker can take to process
  tasks of this activity type.  This overrides the default
  timeout specified when registering the activity type.

  The value should be a number of seconds (integer) or the symbol
  +:none+ (implying no timeout).

@option options [String] :task_list (nil)

  If set, specifies the name of the task list in which to schedule
  the activity task. If not specified, the default task list
  registered with the activity type will be used.

@return [nil]

Requests a signal to be delivered to the specified external workflow execution and records a SignalExternalWorkflowExecutionRequested event in the history.

@param [String] workflow_id

@param [String] run_id

@param [String] signal_name

@param [Hash] options

@option options [String] :control (nil) Optional data attached to

  the event that can be used by the decider in subsequent decision
  tasks.

@option options [String] :input (nil) Optional input to be provided

  with the signal.  The target workflow execution will use the
  signal name and input to process the signal.

@return [nil]

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.

@param [WorkflowType,Hash] workflow_type (nil) The type of

  workflow execution to start.  This should be a {WorkflowType} object
  or a hash with the keys +:name+ and +:version+.

@param [Hash] options

@option (see WorkflowType#start_execution)

@option options [String] :control (nil) Optional data attached to

  the event that can be used by the decider in subsequent workflow
  tasks.

@return [String] Returns the workflow id of the new execution.

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.

@param [Integer] start_to_fire_timeout (nil) The duration to wait

  before firing the timer.

@param [Hash] options

@option options [String] :control (nil) Optional data attached to

  the event that can be used by the decider in subsequent workflow
  tasks.

@option options [String] :timer_id (nil) Unique id for the timer.

  If you do not pass this option, a UUID will be generated.

@return [String] Returns the id of the timer.

Protected Instance methods

[Validate]