Class: AWS::SimpleWorkflow::ActivityTaskCollection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#domainDomain (readonly)

Returns:



31
32
33
# File 'lib/aws/simple_workflow/activity_task_collection.rb', line 31

def domain
  @domain
end

Instance Method Details

#count(task_list) ⇒ Count

Note:

This operation is eventually consistent. The results are best effort and may not exactly reflect recent updates and changes.

Returns the number of tasks in the specified task_list.

count = activity_tasks.count('task-list-name')
count.truncated? #=> false
count.to_i #=> 7

Parameters:

  • task_list (String)

    The name of the task list.

Returns:

  • (Count)

    Returns a possibly truncated count of pending activity tasks for the given task_list.



47
48
49
50
51
52
53
# File 'lib/aws/simple_workflow/activity_task_collection.rb', line 47

def count task_list
  options = {}
  options[:domain] = domain.name
  options[:task_list] = { :name => task_list }
  response = client.count_pending_activity_tasks(options)
  Count.new(response.data['count'], response.data['truncated'])
end

#poll(task_list, options = {}, &block) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/aws/simple_workflow/activity_task_collection.rb', line 108

def poll task_list, options = {}, &block
  loop do 
    begin
      poll_for_single_task(task_list, options) do |activity_task|
        yield(activity_task)
      end
    rescue Timeout::Error
      retry
    end
  end
  nil
end

#poll_for_single_task(task_list, options = {}) {|activity_task| ... } ⇒ ActivityTask?

Returns an activity task when one is available, nil otherwise. If you call this function with a block, nil is always returned.

Parameters:

  • task_list (String)

    The task list to check for pending activity tasks in.

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

Options Hash (options):

  • :identity (String) — default: nil

    Identity of the worker making the request, which is recorded in the ActivityTaskStarted event in the workflow history. This enables diagnostic tracing when problems arise. The :identity defaults to the hostname and pid (e.g. “hostname:pid”).

Yield Parameters:

  • activity_task (ActivityTask)

    Yields if a task is available within 60 seconds.

Returns:

  • (ActivityTask, nil)

    Returns an activity task when one is available, nil otherwise. If you call this function with a block, nil is always returned.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/aws/simple_workflow/activity_task_collection.rb', line 73

def poll_for_single_task task_list, options = {}, &block

  client_opts = {}
  client_opts[:domain] = domain.name
  client_opts[:task_list] = { :name => task_list }
  client_opts[:identity] = identity_opt(options)

  response = client.poll_for_activity_task(client_opts)

  if response.data['taskToken']
    activity_task = ActivityTask.new(domain, response.data)
    if block_given?
      begin
        yield(activity_task)
        activity_task.complete! unless activity_task.responded?
      rescue ActivityTask::CancelRequestedError
        activity_task.cancel! unless activity_task.responded?
      rescue StandardError => e
        unless activity_task.responded?
          reason = "UNTRAPPED ERROR: #{e.message}"
          details = e.backtrace.join("\n")
          activity_task.fail!(:reason => reason, :details => details)
        end
        raise e
      end
      nil
    else
      activity_task
    end
  else
    nil
  end

end