Module: Ntswf::ActivityWorker

Includes:
Worker
Defined in:
lib/ntswf/activity_worker.rb

Overview

Interface for a worker executing tasks

Constant Summary

Constants included from Worker

Worker::RETRY

Instance Method Summary collapse

Methods included from Worker

#in_subprocess

Methods included from Base

#activity_name, #activity_task_lists, #activity_type, #configure, #decision_task_list, #default_unit, #domain, #execution_id_prefix, #execution_version, #notify, #on_notify, #parse_input, #separator, #swf, #workflow_name, #workflow_version

Instance Method Details

#on_activity(proc = nil) {|task| ... } ⇒ Object

Configure a proc or block to be called on receiving an AWS::SimpleWorkflow::ActivityTask

Parameters:

  • proc (Proc) (defaults to: nil)

    The callback

Yield Parameters:

  • task (Hash)

    Description of the task’s properties:

    :activity_task

    The AWS::SimpleWorkflow::ActivityTask

    :name

    Kind of task

    :params

    Custom parameters given to the execution (parsed back from JSON)

    :run_id

    The workflow execution’s run ID

    :version

    Client version

    :workflow_id

    The workflow execution’s workflow ID

    See Client#start_execution‘s options for details

Yield Returns:

  • (Hash)

    Processing result. The following keys are interpreted accordingly:

    :error

    Fails the task with the given error details.

    :outcome

    Completes the task, storing the outcome’s value (as JSON).

    :seconds_until_restart

    Starts the task as new, after the given delay.

    :seconds_until_retry

    Re-schedules the task, after the given delay. In combination with an :error: Marks the task for immediate re-scheduling, ignoring the value. Please note that the behaviour is undefined if an :interval option has been set.



31
32
33
# File 'lib/ntswf/activity_worker.rb', line 31

def on_activity(proc = nil, &block)
  @task_callback = proc || block
end

#process_activitiesObject

Start the worker loop for activity tasks.



36
37
38
# File 'lib/ntswf/activity_worker.rb', line 36

def process_activities
  loop { in_subprocess :process_activity_task }
end

#process_activity_taskObject



40
41
42
43
44
45
46
# File 'lib/ntswf/activity_worker.rb', line 40

def process_activity_task
  announce("polling for activity task #{activity_task_list}")
  domain.activity_tasks.poll_for_single_task(activity_task_list) do |activity_task|
    announce("got activity task #{activity_task.activity_type.inspect} #{activity_task.input}")
    process_single_task activity_task
  end
end