aws-flow 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,9 +17,11 @@ module AWS
17
17
  module Flow
18
18
 
19
19
 
20
- # A decision task handler to work with a {WorkflowTaskPoller}. Create a `DecisionTaskHandler` and pass it to
21
- # {WorkflowTaskPoller} on {WorkflowTaskPoller#initialize construction}.
20
+ # A decision task handler to work with a {WorkflowTaskPoller}. Create a
21
+ # `DecisionTaskHandler` and pass it to {WorkflowTaskPoller} on
22
+ # {WorkflowTaskPoller#initialize construction}.
22
23
  class DecisionTaskHandler
24
+ attr_reader :workflow_definition_map
23
25
 
24
26
  # Creates a new `DecisionTaskHandler`.
25
27
  #
@@ -31,7 +33,7 @@ module AWS
31
33
  def initialize(workflow_definition_map, options=nil)
32
34
  @workflow_definition_map = workflow_definition_map
33
35
  @logger = options.logger if options
34
- @logger ||= Utilities::LogFactory.make_logger(self, "debug")
36
+ @logger ||= Utilities::LogFactory.make_logger(self)
35
37
  end
36
38
 
37
39
 
@@ -41,11 +43,8 @@ module AWS
41
43
  #
42
44
  def handle_decision_task(decision_task_iterator)
43
45
  history_helper = HistoryHelper.new(decision_task_iterator)
44
- @logger.debug "made history_helper"
45
46
  decider = create_async_decider(history_helper)
46
- @logger.debug "made async_decider"
47
47
  decider.decide
48
- @logger.debug "decided"
49
48
  decisions = decider.get_decisions
50
49
  response = {:task_token => decider.task_token}
51
50
  context_data = decider.decision_helper.workflow_context_data
@@ -72,5 +71,4 @@ module AWS
72
71
  end
73
72
 
74
73
  end
75
-
76
74
  end
@@ -44,26 +44,30 @@ module AWS
44
44
  @domain = domain
45
45
  @task_list = task_list
46
46
  @logger = options.logger if options
47
- @logger ||= Utilities::LogFactory.make_logger(self, "debug")
47
+ @logger ||= Utilities::LogFactory.make_logger(self)
48
48
  end
49
49
 
50
50
 
51
51
 
52
+ # @api private
52
53
  # Retrieves any decision tasks that are ready.
53
- def get_decision_tasks
54
+ def get_decision_task
54
55
  @domain.decision_tasks.poll_for_single_task(@task_list)
55
56
  end
56
57
 
57
58
  def poll_and_process_single_task
58
59
  # TODO waitIfSuspended
59
60
  begin
60
- @logger.debug "Starting a new task...\n\n\n"
61
- tasks = get_decision_tasks
62
- return false if tasks.nil?
63
- @logger.debug "We have this many tasks #{tasks}"
64
- @logger.debug "debugging on #{tasks}\n"
65
- task_completed_request = @handler.handle_decision_task(tasks)
66
- @logger.debug "task to be responded to with #{task_completed_request}\n"
61
+ @logger.debug "Polling for a new decision task of type #{@handler.workflow_definition_map.keys.map{ |x| "#{x.name} #{x.version}"} } on task_list: #{@task_list}"
62
+ task = get_decision_task
63
+ if task.nil?
64
+ @logger.debug "Didn't get a task on task_list: #{@task_list}"
65
+ return false
66
+ end
67
+ @logger.info Utilities.workflow_task_to_debug_string("Got decision task", task)
68
+
69
+ task_completed_request = @handler.handle_decision_task(task)
70
+ @logger.debug "Response to the task will be #{task_completed_request}"
67
71
  if !task_completed_request[:decisions].empty? && (task_completed_request[:decisions].first.keys.include?(:fail_workflow_execution_decision_attributes))
68
72
  fail_hash = task_completed_request[:decisions].first[:fail_workflow_execution_decision_attributes]
69
73
  reason = fail_hash[:reason]
@@ -71,11 +75,11 @@ module AWS
71
75
  @logger.debug "#{reason}, #{details}"
72
76
  end
73
77
  @service.respond_decision_task_completed(task_completed_request)
78
+ @logger.info Utilities.workflow_task_to_debug_string("Finished executing task", task)
74
79
  rescue AWS::SimpleWorkflow::Errors::UnknownResourceFault => e
75
- @logger.error "Error in the poller, #{e}"
76
- @logger.error "The error class in #{e.class}"
80
+ @logger.error "Error in the poller, #{e.class}, #{e}"
77
81
  rescue Exception => e
78
- @logger.error "Error in the poller, #{e}"
82
+ @logger.error "Error in the poller, #{e.class}, #{e}"
79
83
  end
80
84
  end
81
85
  end
@@ -118,7 +122,7 @@ module AWS
118
122
  @task_list = task_list
119
123
  @activity_definition_map = activity_definition_map
120
124
  @logger = options.logger if options
121
- @logger ||= Utilities::LogFactory.make_logger(self, "debug")
125
+ @logger ||= Utilities::LogFactory.make_logger(self)
122
126
  @executor = executor
123
127
  end
124
128
 
@@ -133,20 +137,35 @@ module AWS
133
137
  activity_type = task.activity_type
134
138
  begin
135
139
  context = ActivityExecutionContext.new(@service, @domain, task)
136
- activity_implementation = @activity_definition_map[activity_type]
137
- raise "This activity worker was told to work on activity type #{activity_type.name}, but this activity worker only knows how to work on #{@activity_definition_map.keys.map(&:name).join' '}" unless activity_implementation
140
+ unless activity_implementation = @activity_definition_map[activity_type]
141
+ raise "This activity worker was told to work on activity type #{activity_type.name}.#{activity_type.version}, but this activity worker only knows how to work on #{@activity_definition_map.keys.map(&:name).join' '}"
142
+ end
143
+
138
144
  output, original_result, too_large = activity_implementation.execute(task.input, context)
139
- @logger.debug "Responding on task_token #{task.task_token} for task #{task}"
145
+
146
+ @logger.debug "Responding on task_token #{task.task_token} for task #{task}."
140
147
  if too_large
141
- @logger.warn "The output of this activity was too large (greater than 2^15), and therefore aws-flow could not return it to SWF. aws-flow is now attempting to mark this activity as failed. For reference, the result was #{original_result}"
142
- respond_activity_task_failed_with_retry(task.task_token, "An activity cannot send a response with a result larger than 32768 characters. Please reduce the response size. A truncated prefix output is included in the details field.", output)
148
+ @logger.error "Activity #{activity_type.name}.#{activity_type.version} failed: The output of this activity was too large (greater than 2^15), and therefore aws-flow could not return it to SWF. aws-flow is now attempting to mark this activity as failed. For reference, the result was #{original_result}"
149
+
150
+ respond_activity_task_failed_with_retry(
151
+ task.task_token,
152
+ "An activity cannot send a response with a result larger than 32768 characters. Please reduce the response size. A truncated prefix output is included in the details field.",
153
+ output
154
+ )
143
155
  elsif ! activity_implementation.execution_options.manual_completion
144
- @service.respond_activity_task_completed(:task_token => task.task_token, :result => output)
156
+ @service.respond_activity_task_completed(
157
+ :task_token => task.task_token,
158
+ :result => output
159
+ )
145
160
  end
146
161
  rescue ActivityFailureException => e
147
- @logger.error "The activity failed, with original output of #{original_result} and dataconverted result of #{output}. aws-flow will now attempt to fail it."
148
- respond_activity_task_failed_with_retry(task.task_token, e.message, e.details)
162
+ @logger.error "Activity #{activity_type.name}.#{activity_type.version} with input #{task.input} failed with exception #{e}."
149
163
 
164
+ respond_activity_task_failed_with_retry(
165
+ task.task_token,
166
+ e.message,
167
+ e.details
168
+ )
150
169
  end
151
170
  #TODO all the completion stuffs
152
171
  end
@@ -267,10 +286,10 @@ module AWS
267
286
  begin
268
287
  execute(task)
269
288
  rescue CancellationException => e
289
+ @logger.error "Got an error, #{e.message}, while executing #{task.activity_type.name}."
270
290
  respond_activity_task_canceled_with_retry(task.task_token, e.message)
271
291
  rescue Exception => e
272
- @logger.error "Got an error, #{e.message}, while executing #{task.activity_type.name}"
273
- @logger.error "Full stack trace: #{e.backtrace}"
292
+ @logger.error "Got an error, #{e.message}, while executing #{task.activity_type.name}. Full stack trace: #{e.backtrace}"
274
293
  respond_activity_task_failed_with_retry(task.task_token, e.message, e.backtrace)
275
294
  #Do rescue stuff
276
295
  ensure
@@ -278,7 +297,7 @@ module AWS
278
297
  end
279
298
  rescue Exception => e
280
299
  semaphore_needs_release = true
281
- @logger.error "Got into the other error mode"
300
+ @logger.error "Got into the other error mode: #{e}"
282
301
  raise e
283
302
  ensure
284
303
  @poll_semaphore.release if semaphore_needs_release
@@ -300,26 +319,23 @@ module AWS
300
319
  @poll_semaphore ||= SuspendableSemaphore.new
301
320
  @poll_semaphore.acquire
302
321
  semaphore_needs_release = true
303
- @logger.debug "before the poll\n\n"
304
- # This is to warm the lazily loaded clients in the @service, so we don't
305
- # pay for their loading in every forked client
322
+ @logger.debug "Before the poll"
306
323
  begin
307
324
  if use_forking
308
325
  @executor.block_on_max_workers
309
326
  end
327
+ @logger.debug "Polling for a new activity task of type #{@activity_definition_map.keys.map{ |x| "#{x.name} #{x.version}"} } on task_list: #{@task_list}"
310
328
  task = @domain.activity_tasks.poll_for_single_task(@task_list)
311
329
  if task
312
- @logger.info "got a task, #{task.activity_type.name}"
313
- @logger.info "The task token I got was: #{task.task_token}"
330
+ @logger.info Utilities.activity_task_to_debug_string("Got activity task", task)
314
331
  end
315
332
  rescue Exception => e
316
- @logger.error "I have not been able to poll successfully, and am now bailing out, with error #{e}"
333
+ @logger.error "Error in the poller, #{e.class}, #{e}"
317
334
  @poll_semaphore.release
318
335
  return false
319
336
  end
320
337
  if task.nil?
321
- "Still polling at #{Time.now}, but didn't get anything"
322
- @logger.debug "Still polling at #{Time.now}, but didn't get anything"
338
+ @logger.debug "Didn't get a task on task_list: #{@task_list}"
323
339
  @poll_semaphore.release
324
340
  return false
325
341
  end
@@ -329,8 +345,7 @@ module AWS
329
345
  else
330
346
  process_single_task(task)
331
347
  end
332
- # process_single_task(task)
333
- @logger.debug "finished executing the task"
348
+ @logger.info Utilities.activity_task_to_debug_string("Finished executing task", task)
334
349
  return true
335
350
  end
336
351
  end
@@ -21,15 +21,25 @@ module AWS
21
21
  module Utilities
22
22
  # @api private
23
23
  class LogFactory
24
- def self.make_logger(klass, name)
25
- logname = "#{Dir.tmpdir}/#{klass.class.to_s}_#{name}"
24
+ def self.make_logger(klass)
25
+ make_logger_with_level(klass, Logger::INFO)
26
+ end
27
+ def self.make_logger_with_level(klass, level)
28
+ logname = "#{Dir.tmpdir}/#{klass.class.to_s}"
26
29
  logname.gsub!(/::/, '-')
27
30
  log = Logger.new(logname)
28
- log.level = Logger::DEBUG
31
+ log.level = level
29
32
  log
30
33
  end
31
34
  end
32
35
 
36
+ def self.workflow_task_to_debug_string(message, task)
37
+ return "#{message} #{task.workflow_type.name}.#{task.workflow_type.version} for execution with workflow_id: #{task.workflow_execution.workflow_id}, run_id: #{task.workflow_execution.run_id}, task_list: #{task.workflow_execution.task_list} with task_token: #{task.task_token}"
38
+ end
39
+ def self.activity_task_to_debug_string(message, task)
40
+ return "#{message} #{task.activity_type.name}.#{task.activity_type.version} with input: #{task.input} and task_token: #{task.task_token}"
41
+ end
42
+
33
43
 
34
44
  # @api private
35
45
  def self.drill_on_future(future)
@@ -16,7 +16,7 @@
16
16
  module AWS
17
17
  module Flow
18
18
  def self.version
19
- "1.1.1"
19
+ "1.2.0"
20
20
  end
21
21
  end
22
22
  end
@@ -41,7 +41,9 @@ module AWS
41
41
  @domain = domain
42
42
  @task_list = task_list_to_poll
43
43
  @options = Utilities::interpret_block_for_options(WorkerOptions, block)
44
- args.each { |klass_or_instance| add_implementation(klass_or_instance) } if args
44
+ if args
45
+ args.each { |klass_or_instance| add_implementation(klass_or_instance) }
46
+ end
45
47
  @shutting_down = false
46
48
  %w{ TERM INT }.each do |signal|
47
49
  Signal.trap(signal) do
@@ -98,10 +100,11 @@ module AWS
98
100
  # Represents an activity type.
99
101
  class ActivityType < GenericType; end
100
102
 
101
- # This worker class is intended for use by the workflow implementation. It is configured with
102
- # a task list and a workflow implementation. The worker class polls for decision tasks in the
103
- # specified task list. When a decision task is received, it creates an instance of the workflow implementation and
104
- # calls the @ execute() decorated method to process the task.
103
+ # This worker class is intended for use by the workflow implementation. It
104
+ # is configured with a task list and a workflow implementation. The worker
105
+ # class polls for decision tasks in the specified task list. When a decision
106
+ # task is received, it creates an instance of the workflow implementation
107
+ # and calls the @ execute() decorated method to process the task.
105
108
  class WorkflowWorker < GenericWorker
106
109
 
107
110
  # The workflow type for this workflow worker.
@@ -121,12 +124,16 @@ module AWS
121
124
  # @param args
122
125
  # The decisions to use.
123
126
  #
124
- def initialize(service, domain, task_list, *args)
127
+ def initialize(service, domain, task_list, *args, &block)
125
128
  @workflow_definition_map = {}
126
129
  @workflow_type_options = []
127
- super(service, domain, task_list, *args)
130
+ @options = Utilities::interpret_block_for_options(WorkerOptions, block)
128
131
 
132
+ @logger = @options.logger if @options
133
+ @logger ||= Utilities::LogFactory.make_logger(self)
134
+ @options.logger ||= @logger if @options
129
135
 
136
+ super(service, domain, task_list, *args)
130
137
  end
131
138
 
132
139
  def set_workflow_implementation_types(workflow_implementation_types)
@@ -151,15 +158,33 @@ module AWS
151
158
  implementation_options = nil
152
159
  get_state_method = workflow_class.get_state_method
153
160
  signals = workflow_class.signals
154
- @workflow_definition_map[workflow_type] = WorkflowDefinitionFactory.new(workflow_class, workflow_type, registration_options, options, execution_method, signals, get_state_method)
155
- # TODO should probably do something like GenericWorkflowWorker#registerWorkflowTypes
156
- workflow_hash = options.get_options([:default_task_start_to_close_timeout, :default_execution_start_to_close_timeout, :default_child_policy], {
157
- :domain => @domain.name,
158
- :name => workflow_type.name,
159
- :version => version
160
- })
161
+
162
+ @workflow_definition_map[workflow_type] = WorkflowDefinitionFactory.new(
163
+ workflow_class,
164
+ workflow_type,
165
+ registration_options,
166
+ options,
167
+ execution_method,
168
+ signals,
169
+ get_state_method
170
+ )
171
+ # TODO should probably do something like
172
+ # GenericWorkflowWorker#registerWorkflowTypes
173
+ workflow_hash = options.get_options(
174
+ [
175
+ :default_task_start_to_close_timeout,
176
+ :default_execution_start_to_close_timeout,
177
+ :default_child_policy
178
+ ], {
179
+ :domain => @domain.name,
180
+ :name => workflow_type.name,
181
+ :version => version
182
+ }
183
+ )
161
184
  if options.default_task_list
162
- workflow_hash.merge!({:default_task_list => {:name => options.default_task_list} })
185
+ workflow_hash.merge!(
186
+ {:default_task_list => {:name => options.default_task_list} }
187
+ )
163
188
  end
164
189
  @workflow_type_options << workflow_hash
165
190
  end
@@ -173,6 +198,7 @@ module AWS
173
198
  begin
174
199
  @service.register_workflow_type(workflow_type_options)
175
200
  rescue AWS::SimpleWorkflow::Errors::TypeAlreadyExistsFault => e
201
+ @logger.warn "#{e.class} while trying to register workflow #{e.message} with options #{workflow_type_options}"
176
202
  # Purposefully eaten up, the alternative is to check first, and who
177
203
  # wants to do two trips when one will do?
178
204
  end
@@ -183,7 +209,8 @@ module AWS
183
209
  # Starts the workflow with a {WorkflowTaskPoller}.
184
210
  #
185
211
  # @param [true,false] should_register
186
- # Indicates whether the workflow needs to be registered with Amazon SWF first. If {#register} was already called
212
+ # Indicates whether the workflow needs to be registered with Amazon SWF
213
+ # first. If {#register} was already called
187
214
  # for this workflow worker, specify `false`.
188
215
  #
189
216
  def start(should_register = true)
@@ -193,14 +220,24 @@ module AWS
193
220
  # TODO Set up throttler
194
221
  # TODO Set up a timeout on the throttler correctly,
195
222
  # TODO Make this a generic poller, go to the right kind correctly
196
- poller = WorkflowTaskPoller.new(@service, @domain, DecisionTaskHandler.new(@workflow_definition_map, @options), @task_list, @options)
223
+
224
+ poller = WorkflowTaskPoller.new(
225
+ @service,
226
+ @domain,
227
+ DecisionTaskHandler.new(@workflow_definition_map, @options),
228
+ @task_list,
229
+ @options
230
+ )
231
+
197
232
  register if should_register
233
+ @logger.debug "Starting an infinite loop to poll and process workflow tasks."
198
234
  loop do
199
235
  run_once(false, poller)
200
236
  end
201
237
  end
202
238
 
203
- # Starts the workflow and runs it once, with an optional {WorkflowTaskPoller}.
239
+ # Starts the workflow and runs it once, with an optional
240
+ # {WorkflowTaskPoller}.
204
241
  #
205
242
  # @param should_register (see #start)
206
243
  #
@@ -209,21 +246,31 @@ module AWS
209
246
  #
210
247
  def run_once(should_register = false, poller = nil)
211
248
  register if should_register
212
- poller = WorkflowTaskPoller.new(@service, @domain, DecisionTaskHandler.new(@workflow_definition_map, @options), @task_list, @options) if poller.nil?
249
+
250
+ poller = WorkflowTaskPoller.new(
251
+ @service,
252
+ @domain,
253
+ DecisionTaskHandler.new(@workflow_definition_map, @options),
254
+ @task_list,
255
+ @options
256
+ ) if poller.nil?
257
+
213
258
  Kernel.exit if @shutting_down
214
259
  poller.poll_and_process_single_task
215
260
  end
216
261
  end
217
262
 
218
263
 
219
- # Used to implement an activity worker. You can use the `ActivityWorker` class to conveniently poll a task list for
220
- # activity tasks.
221
- #
222
- # You configure the activity worker with activity implementation objects. This worker class then polls for activity
223
- # tasks in the specified task list. When an activity task is received, it looks up the appropriate implementation
224
- # that you provided, and calls the activity method to process the task. Unlike the {WorkflowWorker}, which creates a
225
- # new instance for every decision task, the `ActivityWorker` simply uses the object you provided.
264
+ # Used to implement an activity worker. You can use the `ActivityWorker`
265
+ # class to conveniently poll a task list for activity tasks.
226
266
  #
267
+ # You configure the activity worker with activity implementation objects.
268
+ # This worker class then polls for activity tasks in the specified task
269
+ # list. When an activity task is received, it looks up the appropriate
270
+ # implementation that you provided, and calls the activity method to
271
+ # process the task. Unlike the {WorkflowWorker}, which creates a new
272
+ # instance for every decision task, the `ActivityWorker` simply uses the
273
+ # object you provided.
227
274
  class ActivityWorker < GenericWorker
228
275
 
229
276
  # Creates a new `ActivityWorker` instance.
@@ -245,11 +292,17 @@ module AWS
245
292
  @activity_definition_map = {}
246
293
  @activity_type_options = []
247
294
  @options = Utilities::interpret_block_for_options(WorkerOptions, block)
295
+
248
296
  @logger = @options.logger if @options
249
- @logger ||= Utilities::LogFactory.make_logger(self, "debug")
297
+ @logger ||= Utilities::LogFactory.make_logger(self)
298
+ @options.logger ||= @logger if @options
299
+
250
300
  max_workers = @options.execution_workers if @options
251
301
  max_workers = 20 if (max_workers.nil? || max_workers.zero?)
252
- @executor = ForkingExecutor.new(:max_workers => max_workers, :logger => @logger)
302
+ @executor = ForkingExecutor.new(
303
+ :max_workers => max_workers,
304
+ :logger => @logger
305
+ )
253
306
  @shutdown_first_time_function = lambda do
254
307
  @executor.shutdown Float::INFINITY
255
308
  Kernel.exit
@@ -273,8 +326,15 @@ module AWS
273
326
  begin
274
327
  @service.register_activity_type(activity_type_options)
275
328
  rescue AWS::SimpleWorkflow::Errors::TypeAlreadyExistsFault => e
276
- previous_registration = @service.describe_activity_type(:domain => @domain.name, :activity_type => {:name => activity_type_options[:name], :version => activity_type_options[:version]})
277
- default_options = activity_type_options.select {|key, val| key =~ /default/}
329
+ @logger.warn "#{e.class} while trying to register activity #{e.message} with options #{activity_type_options}"
330
+ previous_registration = @service.describe_activity_type(
331
+ :domain => @domain.name,
332
+ :activity_type => {
333
+ :name => activity_type_options[:name],
334
+ :version => activity_type_options[:version]
335
+ }
336
+ )
337
+ default_options = activity_type_options.select { |key, val| key =~ /default/}
278
338
  previous_keys = previous_registration["configuration"].keys.map {|x| camel_case_to_snake_case(x).to_sym}
279
339
 
280
340
  previous_registration = Hash[previous_keys.zip(previous_registration["configuration"].values)]
@@ -282,7 +342,10 @@ module AWS
282
342
  previous_registration[:default_task_list][:name] = previous_registration[:default_task_list].delete("name")
283
343
  end
284
344
  registration_difference = default_options.sort.to_a - previous_registration.sort.to_a
285
- raise "There is a difference between the types you have registered previously and the types you are currently registering, but you haven't changed the version. These new changes will not be picked up. In particular, these options are different #{Hash[registration_difference]}" unless registration_difference.empty?
345
+
346
+ unless registration_difference.empty?
347
+ raise "There is a difference between the types you have registered previously and the types you are currently registering, but you haven't changed the version. These new changes will not be picked up. In particular, these options are different #{Hash[registration_difference]}"
348
+ end
286
349
  # Purposefully eaten up, the alternative is to check first, and who
287
350
  # wants to do two trips when one will do?
288
351
  end
@@ -299,16 +362,28 @@ module AWS
299
362
  instance = (class_or_instance.class == Class) ? class_or_instance.new : class_or_instance
300
363
  klass.activities.each do |activity_type|
301
364
 
302
- #TODO this should assign to an activityImplementation, so that we can call execute on it later
303
- @activity_definition_map[activity_type] = ActivityDefinition.new(instance, activity_type.name.split(".").last, nil, activity_type.options, activity_type.options.data_converter)
365
+ # TODO this should assign to an activityImplementation, so that we can
366
+ # call execute on it later
367
+ @activity_definition_map[activity_type] = ActivityDefinition.new(
368
+ instance,
369
+ activity_type.name.split(".").last,
370
+ nil,
371
+ activity_type.options,
372
+ activity_type.options.data_converter
373
+ )
304
374
  options = activity_type.options
305
375
  option_hash = {
306
376
  :domain => @domain.name,
307
377
  :name => activity_type.name.to_s,
308
378
  :version => activity_type.version
309
379
  }
380
+
310
381
  option_hash.merge!(options.get_default_options)
311
- option_hash.merge!(:default_task_list => {:name => options.default_task_list}) if options.default_task_list
382
+
383
+ option_hash.merge!(
384
+ :default_task_list => {:name => options.default_task_list}
385
+ ) if options.default_task_list
386
+
312
387
  @activity_type_options << option_hash
313
388
  end
314
389
  end
@@ -317,27 +392,49 @@ module AWS
317
392
  # Starts the activity that was added to the `ActivityWorker`.
318
393
  #
319
394
  # @param [true, false] should_register
320
- # Set to `false` if the activity should not register itself (it is already registered).
395
+ # Set to `false` if the activity should not register itself (it is
396
+ # already registered).
321
397
  #
322
398
  def start(should_register = true)
399
+
323
400
  register if should_register
324
- poller = ActivityTaskPoller.new(@service, @domain, @task_list, @activity_definition_map, @executor, @options)
401
+ poller = ActivityTaskPoller.new(
402
+ @service,
403
+ @domain,
404
+ @task_list,
405
+ @activity_definition_map,
406
+ @executor,
407
+ @options
408
+ )
409
+
410
+ @logger.debug "Starting an infinite loop to poll and process activity tasks."
325
411
  loop do
326
412
  run_once(false, poller)
327
413
  end
328
414
  end
329
415
 
330
- # Starts the activity that was added to the `ActivityWorker` and, optionally, sets the {ActivityTaskPoller}.
416
+ # Starts the activity that was added to the `ActivityWorker` and,
417
+ # optionally, sets the {ActivityTaskPoller}.
331
418
  #
332
419
  # @param [true, false] should_register
333
- # Set to `false` if the activity should not register itself (it is already registered).
420
+ # Set to `false` if the activity should not register itself (it is
421
+ # already registered).
334
422
  #
335
423
  # @param [ActivityTaskPoller] poller
336
- # The {ActivityTaskPoller} to use. If this is not set, a default {ActivityTaskPoller} will be created.
424
+ # The {ActivityTaskPoller} to use. If this is not set, a default
425
+ # {ActivityTaskPoller} will be created.
337
426
  #
338
427
  def run_once(should_register = true, poller = nil)
339
428
  register if should_register
340
- poller = ActivityTaskPoller.new(@service, @domain, @task_list, @activity_definition_map, @executor, @options) if poller.nil?
429
+ poller = ActivityTaskPoller.new(
430
+ @service,
431
+ @domain,
432
+ @task_list,
433
+ @activity_definition_map,
434
+ @executor,
435
+ @options
436
+ ) if poller.nil?
437
+
341
438
  Kernel.exit if @shutting_down
342
439
  poller.poll_and_process_single_task(@options.use_forking)
343
440
  end