Class: AWS::Flow::WorkflowTaskPoller

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/decider/task_poller.rb

Instance Method Summary collapse

Constructor Details

#initialize(service, domain, handler, task_list, options = nil) ⇒ WorkflowTaskPoller

Creates a new WorkflowTaskPoller

Parameters:

  • service

    The Amazon SWF service object on which this task poller will operate.

  • domain (String)

    The name of the domain containing the task lists to poll.

  • handler (DecisionTaskHandler)

    A DecisionTaskHandler to handle polled tasks. The poller will call the DecisionTaskHandler#handle_decision_task method.

  • task_list (Array)

    Specifies the task list to poll for decision tasks.

  • options (Object) (defaults to: nil)

    Options to use for the logger.



41
42
43
44
45
46
47
48
# File 'lib/aws/decider/task_poller.rb', line 41

def initialize(service, domain, handler, task_list, options=nil)
  @service = service
  @handler = handler
  @domain = domain
  @task_list = task_list
  @logger = options.logger if options
  @logger ||= Utilities::LogFactory.make_logger(self, "debug")
end

Instance Method Details

#get_decision_tasksObject

Retrieves any decision tasks that are ready.



53
54
55
# File 'lib/aws/decider/task_poller.rb', line 53

def get_decision_tasks
  @domain.decision_tasks.poll_for_single_task(@task_list)
end

#poll_and_process_single_taskObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/aws/decider/task_poller.rb', line 57

def poll_and_process_single_task
  # TODO waitIfSuspended
  begin
    @logger.debug "Starting a new task...\n\n\n"
    tasks = get_decision_tasks
    return false if tasks.nil?
    @logger.debug "We have this many tasks #{tasks}"
    @logger.debug "debugging on #{tasks}\n"
    task_completed_request = @handler.handle_decision_task(tasks)
    @logger.debug "task to be responded to with #{task_completed_request}\n"
    if !task_completed_request[:decisions].empty? && (task_completed_request[:decisions].first.keys.include?(:fail_workflow_execution_decision_attributes))
      fail_hash = task_completed_request[:decisions].first[:fail_workflow_execution_decision_attributes]
      reason = fail_hash[:reason]
      details = fail_hash[:details]
      @logger.debug "#{reason}, #{details}"
    end
    @service.respond_decision_task_completed(task_completed_request)
  rescue AWS::SimpleWorkflow::Errors::UnknownResourceFault => e
    @logger.debug "Error in the poller, #{e}"
    @logger.debug "The error class in #{e.class}"
  rescue Exception => e
    @logger.debug "Error in the poller, #{e}"
  end
end