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.
- checksums.yaml +8 -8
- data/lib/aws/decider/decider.rb +1 -1
- data/lib/aws/decider/executor.rb +36 -30
- data/lib/aws/decider/options.rb +178 -120
- data/lib/aws/decider/task_handler.rb +5 -7
- data/lib/aws/decider/task_poller.rb +49 -34
- data/lib/aws/decider/utilities.rb +13 -3
- data/lib/aws/decider/version.rb +1 -1
- data/lib/aws/decider/worker.rb +137 -40
- data/lib/aws/decider/workflow_client.rb +1 -1
- data/spec/aws/integration/integration_spec.rb +55 -33
- data/spec/aws/unit/decider_spec.rb +22 -19
- data/spec/aws/unit/executor_spec.rb +49 -0
- data/spec/aws/unit/options_spec.rb +293 -0
- data/spec/aws/unit/preinclude_tests.rb +2 -1
- data/spec/spec_helper.rb +1 -0
- metadata +4 -2
@@ -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
|
21
|
-
# {WorkflowTaskPoller} on
|
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
|
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
|
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
|
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 "
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@logger.
|
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
|
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
|
-
|
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
|
-
|
145
|
+
|
146
|
+
@logger.debug "Responding on task_token #{task.task_token} for task #{task}."
|
140
147
|
if too_large
|
141
|
-
@logger.
|
142
|
-
|
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(
|
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 "
|
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 "
|
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 "
|
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 "
|
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
|
-
"
|
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
|
-
|
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
|
25
|
-
|
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 =
|
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)
|
data/lib/aws/decider/version.rb
CHANGED
data/lib/aws/decider/worker.rb
CHANGED
@@ -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
|
-
|
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
|
102
|
-
# a task list and a workflow implementation. The worker
|
103
|
-
#
|
104
|
-
#
|
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
|
-
|
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
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
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!(
|
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
|
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
|
-
|
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
|
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
|
-
|
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`
|
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
|
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(
|
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
|
-
|
277
|
-
|
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
|
-
|
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
|
303
|
-
|
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
|
-
|
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
|
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(
|
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,
|
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
|
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
|
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(
|
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
|