class AWS::SimpleWorkflow::ActivityTaskCollection
Attributes
domain[R]
@return [Domain]
Public Class Methods
new(domain, options = {})
click to toggle source
@api private
Calls superclass method
AWS::Core::Model::new
# File lib/aws/simple_workflow/activity_task_collection.rb, line 25 def initialize domain, options = {} @domain = domain super end
Public Instance Methods
count(task_list)
click to toggle source
Returns the number of tasks in the specified `task_list`.
count = activity_tasks.count('task-list-name') count.truncated? #=> false count.to_i #=> 7
@note This operation is eventually consistent. The results are best
effort and may not exactly reflect recent updates and changes.
@param [String] task_list The name of the task list.
@return [Count] Returns a possibly truncated count of
pending activity tasks for the given `task_list`.
# 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 = {}) { |activity_task| ... }
click to toggle source
# 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| ... }
click to toggle source
@param [String] task_list The task list to check for pending
activity tasks in.
@param [Hash] options
@option options [String] :identity (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").
@yieldparam [ActivityTask] activity_task Yields if a task is
available within 60 seconds.
@return [ActivityTask,nil] Returns an activity task when one is
available, `nil` otherwise. If you call this function with a block, `nil` is always returned.
# 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