aws-flow 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/Rakefile +18 -31
  4. data/aws-flow.gemspec +1 -1
  5. data/lib/aws/decider.rb +1 -2
  6. data/lib/aws/decider/activity.rb +99 -53
  7. data/lib/aws/decider/activity_definition.rb +43 -7
  8. data/lib/aws/decider/async_decider.rb +56 -57
  9. data/lib/aws/decider/async_retrying_executor.rb +4 -5
  10. data/lib/aws/decider/data_converter.rb +2 -2
  11. data/lib/aws/decider/decider.rb +46 -41
  12. data/lib/aws/decider/decision_context.rb +2 -2
  13. data/lib/aws/decider/exceptions.rb +6 -6
  14. data/lib/aws/decider/executor.rb +15 -11
  15. data/lib/aws/decider/flow_defaults.rb +54 -22
  16. data/lib/aws/decider/generic_client.rb +7 -7
  17. data/lib/aws/decider/history_helper.rb +0 -0
  18. data/lib/aws/decider/implementation.rb +5 -5
  19. data/lib/aws/decider/options.rb +285 -155
  20. data/lib/aws/decider/state_machines.rb +10 -10
  21. data/lib/aws/decider/task_handler.rb +5 -5
  22. data/lib/aws/decider/task_poller.rb +152 -15
  23. data/lib/aws/decider/utilities.rb +14 -14
  24. data/lib/aws/decider/version.rb +1 -1
  25. data/lib/aws/decider/worker.rb +21 -20
  26. data/lib/aws/decider/workflow_client.rb +78 -31
  27. data/lib/aws/decider/workflow_clock.rb +1 -1
  28. data/lib/aws/decider/workflow_definition.rb +5 -5
  29. data/lib/aws/decider/workflow_definition_factory.rb +1 -1
  30. data/lib/aws/decider/workflow_enabled.rb +1 -1
  31. data/lib/aws/flow/async_backtrace.rb +19 -18
  32. data/lib/aws/flow/async_scope.rb +32 -16
  33. data/lib/aws/flow/begin_rescue_ensure.rb +61 -56
  34. data/lib/aws/flow/fiber.rb +14 -6
  35. data/lib/aws/flow/flow_utils.rb +9 -6
  36. data/lib/aws/flow/future.rb +43 -18
  37. data/lib/aws/flow/implementation.rb +34 -18
  38. data/lib/aws/flow/simple_dfa.rb +12 -4
  39. data/lib/aws/flow/tasks.rb +120 -86
  40. data/{test/aws → spec/aws/integration}/integration_spec.rb +0 -0
  41. data/{test/aws → spec/aws/unit}/async_backtrace_spec.rb +1 -0
  42. data/{test/aws → spec/aws/unit}/async_scope_spec.rb +0 -0
  43. data/{test/aws → spec/aws/unit}/begin_rescue_ensure_spec.rb +90 -2
  44. data/{test/aws → spec/aws/unit}/decider_spec.rb +41 -53
  45. data/{test/aws → spec/aws/unit}/external_task_spec.rb +0 -0
  46. data/{test/aws → spec/aws/unit}/factories.rb +0 -0
  47. data/{test/aws → spec/aws/unit}/fiber_condition_variable_spec.rb +0 -0
  48. data/{test/aws → spec/aws/unit}/fiber_spec.rb +0 -0
  49. data/{test/aws → spec/aws/unit}/flow_spec.rb +0 -0
  50. data/{test/aws → spec/aws/unit}/future_spec.rb +0 -0
  51. data/{test/aws → spec/aws/unit}/preinclude_tests.rb +0 -0
  52. data/{test/aws → spec/aws/unit}/rubyflow.rb +0 -0
  53. data/{test/aws → spec/aws/unit}/simple_dfa_spec.rb +0 -0
  54. data/{test/aws → spec}/spec_helper.rb +0 -0
  55. metadata +30 -30
@@ -24,7 +24,7 @@ module AWS
24
24
  class ActivityDefinition
25
25
  attr_accessor :execution_options
26
26
 
27
- # Creates a new ActivityDefinition instance
27
+ # Creates a new ActivityDefinition instance.
28
28
  #
29
29
  # @param [Object] instance
30
30
  #
@@ -46,12 +46,10 @@ module AWS
46
46
  @converter = converter
47
47
  end
48
48
 
49
- # Executes the activity
50
- #
51
- # === Parameters
49
+ # Executes the activity.
52
50
  #
53
51
  # @param [Object] input
54
- # Optional input for the activity execution.
52
+ # Additional input for the activity execution.
55
53
  #
56
54
  # @param [ActivityExecutionContext] context
57
55
  # The context for the activity execution.
@@ -60,10 +58,10 @@ module AWS
60
58
  begin
61
59
  @instance._activity_execution_context = context
62
60
  # Since we encode all the inputs in some converter, and these inputs
63
- # are not "true" ruby objects yet, there is no way for that input to
61
+ # are not "true" Ruby objects yet, there is no way for that input to
64
62
  # be an instance of the NilClass(the only thing that responds true to
65
63
  # .nil?) and thus we can be assured that if input.nil?, then the
66
- # method had no input
64
+ # method had no input.
67
65
  if input.nil?
68
66
  result = @instance.send(@activity_method)
69
67
  else
@@ -87,21 +85,59 @@ module AWS
87
85
 
88
86
  end
89
87
 
88
+ # The execution context for an activity task.
90
89
  class ActivityExecutionContext
91
90
  attr_accessor :service, :domain, :task
91
+
92
+ # Initializes a new `ActivityExecutionContext` object.
93
+ #
94
+ # @param [AWS::SimpleWorkflow] service
95
+ # An instance of [AWS::SimpleWorkflow](http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SimpleWorkflow.html) to
96
+ # set for the activity execution context.
97
+ #
98
+ # @param [AWS::SimpleWorkflow::Domain] domain
99
+ # The [AWS::SimpleWorkflow::Domain](http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SimpleWorkflow/Domain.html)
100
+ # in which the activity task is running.
101
+ #
102
+ # @param [AWS::SimpleWorkflow::ActivityTask] task
103
+ # The
104
+ # [AWS::SimpleWorkflow::ActivityTask](http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SimpleWorkflow/ActivityTask.html)
105
+ # that this execution context is for.
106
+ #
92
107
  def initialize(service, domain, task)
93
108
  @service = service
94
109
  @domain = domain
95
110
  @task = task
96
111
  end
112
+
113
+ # Gets the [task
114
+ # token](http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SimpleWorkflow/ActivityTask.html#task_token-instance_method),
115
+ # an opaque string that can be used to uniquely identify this task execution.
116
+ # @return [String] the activity task token.
97
117
  def task_token
98
118
  @task.task_token
99
119
  end
100
120
 
121
+ # Gets the
122
+ # [AWS::SimpleWorkflow::WorkflowExecution](http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SimpleWorkflow/WorkflowExecution.html)
123
+ # instance that is the context for this activity execution.
124
+ #
125
+ # @return [AWS::SimpleWorkflow::WorkflowExecution]
126
+ # The `WorkflowExecution` in this activity execution context.
127
+ #
101
128
  def workflow_execution
102
129
  @task.workflow_execution
103
130
  end
104
131
 
132
+ # Records a heartbeat for the activity, indicating to Amazon SWF that the activity is still making progress.
133
+ #
134
+ # @param [String] details
135
+ # If specified, contains details about the progress of the activity task. Up to 2048
136
+ # characters can be provided.
137
+ #
138
+ # @raise [CancellationException]
139
+ # The activity task has been cancelled.
140
+ #
105
141
  def record_activity_heartbeat(details)
106
142
  to_send = {:task_token => task_token.to_s, :details => details.to_s }
107
143
  response = @service.record_activity_task_heartbeat(to_send)
@@ -16,26 +16,26 @@
16
16
  module AWS
17
17
  module Flow
18
18
 
19
- # Represents a decision ID
19
+ # Represents a decision ID.
20
20
  class DecisionID
21
21
 
22
- # Creates a new DecisionID
22
+ # Creates a new decision ID.
23
23
  #
24
24
  # @param decision_target
25
- # The decision target
25
+ # The decision target.
26
26
  #
27
27
  # @param string_id
28
- # The string that identifies this decisison
28
+ # The string that identifies this decision.
29
29
  #
30
30
  def initialize(decision_target, string_id)
31
31
  @decision_target = decision_target
32
32
  @string_id = string_id
33
33
  end
34
34
 
35
- # Hash function to return an unique value for the DecisionID
35
+ # Hash function to return an unique value for the decision ID.
36
36
  #
37
37
  # @return
38
- # The calculated hash value for the DecisionID.
38
+ # The calculated hash value for the decision ID.
39
39
  #
40
40
  def hash
41
41
  prime = 31
@@ -45,20 +45,20 @@ module AWS
45
45
  result
46
46
  end
47
47
 
48
- # Is this Decision ID the same as another?
48
+ # Is this decision ID the same as another?
49
49
  #
50
50
  # @param [Object] other
51
51
  # The object to compare with.
52
52
  #
53
53
  # @return [true, false]
54
- # Returns `true` if the object is the same as this DecisionID; `false` otherwise.
54
+ # Returns `true` if the object is the same as this decision ID; `false` otherwise.
55
55
  #
56
56
  def eql?(other)
57
57
 
58
58
  end
59
59
  end
60
60
 
61
- # @!visibility private
61
+ # @api private
62
62
  class DecisionWrapper
63
63
  #TODO Consider taking out the id, it's unclear if it is needed
64
64
  def initialize(id, decision, options = [])
@@ -66,11 +66,11 @@ module AWS
66
66
  @id = id
67
67
  end
68
68
 
69
- # @!visibility private
69
+ # @api private
70
70
  def get_decision
71
71
  @decision
72
72
  end
73
- # @!visibility private
73
+ # @api private
74
74
  def consume(symbol)
75
75
  # quack like a state machine
76
76
  end
@@ -81,7 +81,7 @@ module AWS
81
81
  end
82
82
 
83
83
 
84
- # A decision helper for a workflow
84
+ # A decision helper for a workflow.
85
85
  #
86
86
  # @!attribute [Hash] activity_options
87
87
  #
@@ -99,7 +99,7 @@ module AWS
99
99
  #
100
100
  # @!attribute [Hash] signal_initiated_event_to_signal_id
101
101
  #
102
- # @!visibility private
102
+ # @api private
103
103
  class DecisionHelper
104
104
  attr_accessor :decision_map, :activity_scheduling_event_id_to_activity_id, :scheduled_activities, :scheduled_timers, :activity_options, :scheduled_external_workflows, :scheduled_signals, :signal_initiated_event_to_signal_id, :child_initiated_event_id_to_workflow_id, :workflow_context_data
105
105
  class << self
@@ -123,13 +123,13 @@ module AWS
123
123
  @child_initiated_event_id_to_workflow_id = {}
124
124
  end
125
125
 
126
- # @!visibility private
126
+ # @api private
127
127
  def get_next_id(decision_target)
128
128
  id = (@id[decision_target] += 1)
129
129
  "#{decision_target}#{id}"
130
130
  end
131
131
 
132
- # @!visibility private
132
+ # @api private
133
133
  def get_next_state_machine_which_will_schedule(list)
134
134
  return if list.empty?
135
135
  ele = list.shift
@@ -141,11 +141,11 @@ module AWS
141
141
  DecisionHelper.completion_events.include? decision.get_decision[:decision_type].to_sym
142
142
  end
143
143
 
144
- # @!visibility private
144
+ # @api private
145
145
  def handle_decision_task_started_event
146
146
  # In order to ensure that the events we have already scheduled do not
147
147
  # make a decision, we will process only maximum_decisions_per_completion
148
- # here
148
+ # here.
149
149
  count = 0
150
150
  decision_list = @decision_map.values
151
151
  decision_state_machine = get_next_state_machine_which_will_schedule(decision_list)
@@ -166,31 +166,30 @@ module AWS
166
166
  end
167
167
  end
168
168
 
169
-
170
- def [](key)
171
- return @decision_map[key]
172
- end
173
- def []=(key, val)
174
- return @decision_map[key] = val
169
+ # @api private
170
+ def method_missing(method_name, *args)
171
+ if [:[]=, :[]].include? method_name
172
+ @decision_map.send(method_name, *args)
173
+ end
175
174
  end
176
175
 
177
- # Returns the activity ID for a scheduled activity
176
+ # Returns the activity ID for a scheduled activity.
178
177
  #
179
178
  # @param [String] scheduled_id
180
179
  # The scheduled activity ID.
181
180
  #
182
- # @!visibility private
181
+ # @api private
183
182
  def get_activity_id(scheduled_id)
184
183
  activity_scheduling_event_id_to_activity_id[scheduled_id]
185
184
  end
186
185
  end
187
186
 
188
- # The asynchronous decider class
187
+ # Represents an asynchronous decider class.
189
188
  class AsyncDecider
190
189
  include Utilities::SelfMethods
191
190
  attr_accessor :task_token, :decision_helper
192
191
 
193
- # Creates a new asynchronous decider
192
+ # Creates a new asynchronous decider.
194
193
  def initialize(workflow_definition_factory, history_helper, decision_helper)
195
194
  @workflow_definition_factory = workflow_definition_factory
196
195
  @history_helper = history_helper
@@ -207,7 +206,7 @@ module AWS
207
206
  # @note *Beware, this getter will modify things*, as it creates decisions for the objects in the {AsyncDecider}
208
207
  # that need decisions sent out.
209
208
  #
210
- # @!visibility private
209
+ # @api private
211
210
  def get_decisions
212
211
  result = @decision_helper.decision_map.values.map {|decision_object|
213
212
  decision_object.get_decision}.compact
@@ -221,7 +220,7 @@ module AWS
221
220
  return result
222
221
  end
223
222
 
224
- # @!visibility private
223
+ # @api private
225
224
  def decide
226
225
  begin
227
226
  decide_impl
@@ -241,7 +240,7 @@ module AWS
241
240
  end
242
241
  end
243
242
 
244
- # @!visibility private
243
+ # @api private
245
244
  def decide_impl
246
245
  single_decision_event = @history_helper.get_single_decision_events
247
246
  while single_decision_event.length > 0
@@ -289,7 +288,7 @@ module AWS
289
288
 
290
289
  # If you don't have details, you must be some other type of
291
290
  # exception. We can't do anything exceedingly clever, so lets just get
292
- # the stack trace and pop that out
291
+ # the stack trace and pop that out.
293
292
  details = failure.details if (failure.respond_to? :details)
294
293
  details ||= failure.backtrace.join("")
295
294
  new_details = details[0..(max_response_size - truncation_overhead)]
@@ -314,7 +313,7 @@ module AWS
314
313
  # Continues this as a new workflow, using the provided decision and options.
315
314
  #
316
315
  # @param [DecisionID] decision_id
317
- # The decision id to use.
316
+ # The decision ID to use.
318
317
  #
319
318
  # @param [WorkflowOptions] continue_as_new_options
320
319
  # The options to use for the new workflow.
@@ -359,7 +358,7 @@ module AWS
359
358
  end
360
359
  end
361
360
 
362
- # Is the task completed?
361
+ # Indicates whether the task completed.
363
362
  #
364
363
  # @return [true, false]
365
364
  # Returns `true` if the task is completed; `false` otherwise.
@@ -371,7 +370,7 @@ module AWS
371
370
  # Handler for the `:ActivityTaskScheduled` event.
372
371
  #
373
372
  # @param [Object] event
374
- # The event to process
373
+ # The event to process.
375
374
  #
376
375
  def handle_activity_task_scheduled(event)
377
376
  activity_id = event.attributes[:activity_id]
@@ -383,7 +382,7 @@ module AWS
383
382
  # Handler for the `:WorkflowExecutionStarted` event.
384
383
  #
385
384
  # @param [Object] event
386
- # The event to process
385
+ # The event to process.
387
386
  #
388
387
  def handle_workflow_execution_started(event)
389
388
  @workflow_async_scope = AsyncScope.new do
@@ -397,7 +396,7 @@ module AWS
397
396
  # Handler for the `:TimerFired` event.
398
397
  #
399
398
  # @param [Object] event
400
- # The event to process
399
+ # The event to process.
401
400
  #
402
401
  def handle_timer_fired(event)
403
402
  timer_id = event.attributes[:timer_id]
@@ -413,7 +412,7 @@ module AWS
413
412
  # Handler for the `:StartTimerFailed` event.
414
413
  #
415
414
  # @param [Object] event
416
- # The event to process
415
+ # The event to process.
417
416
  #
418
417
  def handle_start_timer_failed(event)
419
418
  timer_id = event.attributes.timer_id
@@ -434,7 +433,7 @@ module AWS
434
433
 
435
434
  # Handler for the `:WorkflowExecutionCancelRequested` event.
436
435
  # @param [Object] event
437
- # The event to process
436
+ # The event to process.
438
437
  def handle_workflow_execution_cancel_requested(event)
439
438
  @workflow_async_scope.cancel(CancellationException.new("Cancelled from a WorkflowExecutionCancelRequested"))
440
439
  @cancel_requested = true
@@ -442,7 +441,7 @@ module AWS
442
441
 
443
442
  # Handler for the `:ActivityTaskCancelRequested` event.
444
443
  # @param [Object] event
445
- # The event to process
444
+ # The event to process.
446
445
  def handle_activity_task_cancel_requested(event)
447
446
  activity_id = event.attributes[:activity_id]
448
447
  @decision_helper[activity_id].consume(:handle_cancellation_initiated_event)
@@ -450,7 +449,7 @@ module AWS
450
449
 
451
450
  # Handler for the `:RequestCancelActivityTaskFailed` event.
452
451
  # @param [Object] event
453
- # The event to process
452
+ # The event to process.
454
453
  def handle_request_cancel_activity_task_failed(event)
455
454
  handle_event(event, {
456
455
  :id_methods => [:activity_id],
@@ -465,7 +464,7 @@ module AWS
465
464
 
466
465
  # Handler for the `:CompleteWorkflowExecutionFailed` event.
467
466
  # @param [Object] event
468
- # The event to process
467
+ # The event to process.
469
468
  def handle_complete_workflow_execution_failed(event)
470
469
  handle_closing_failure
471
470
  end
@@ -473,7 +472,7 @@ module AWS
473
472
  # Handler for the `:FailWorkflowExecutionFailed` event.
474
473
  #
475
474
  # @param [Object] event
476
- # The event to process
475
+ # The event to process.
477
476
  #
478
477
  def handle_fail_workflow_execution_failed(event)
479
478
  handle_closing_failure
@@ -482,16 +481,16 @@ module AWS
482
481
  # Handler for the `:CancelWorkflowExecutionFailed` event.
483
482
  #
484
483
  # @param [Object] event
485
- # The event to process
484
+ # The event to process.
486
485
  #
487
486
  def handle_cancel_workflow_execution_failed(event)
488
487
  handle_closing_failure
489
488
  end
490
489
 
491
- # Handler for the `:ContinueAsNewWorkflowExecutionFailed' event.
490
+ # Handler for the `:ContinueAsNewWorkflowExecutionFailed` event.
492
491
  #
493
492
  # @param [Object] event
494
- # The event to process
493
+ # The event to process.
495
494
  #
496
495
  def handle_continue_as_new_workflow_execution_failed(event)
497
496
  handle_closing_failure
@@ -500,7 +499,7 @@ module AWS
500
499
  # Handler for the `:TimerStarted` event.
501
500
  #
502
501
  # @param [Object] event
503
- # The event to process
502
+ # The event to process.
504
503
  #
505
504
  def handle_timer_started(event)
506
505
  timer_id = event.attributes[:timer_id]
@@ -512,7 +511,7 @@ module AWS
512
511
  # Handler for the `:TimerCanceled` event.
513
512
  #
514
513
  # @param [Object] event
515
- # The event to process
514
+ # The event to process.
516
515
  #
517
516
  def handle_timer_canceled(event)
518
517
  handle_event(event, {
@@ -531,7 +530,7 @@ module AWS
531
530
  # Handler for the `:SignalExternalWorkflowExecutionInitiated` event.
532
531
  #
533
532
  # @param [Object] event
534
- # The event to process
533
+ # The event to process.
535
534
  #
536
535
  def handle_signal_external_workflow_execution_initiated(event)
537
536
  signal_id = event.attributes[:control]
@@ -543,7 +542,7 @@ module AWS
543
542
  # Handler for the `:RequestCancelExternalWorkflowExecutionInitiated` event.
544
543
  #
545
544
  # @param [Object] event
546
- # The event to process
545
+ # The event to process.
547
546
  #
548
547
  def handle_request_cancel_external_workflow_execution_initiated(event)
549
548
  handle_event(event, {
@@ -555,7 +554,7 @@ module AWS
555
554
  # Handler for the `:RequestCancelExternalWorkflowExecutionFailed` event.
556
555
  #
557
556
  # @param [Object] event
558
- # The event to process
557
+ # The event to process.
559
558
  #
560
559
  def handle_request_cancel_external_workflow_execution_failed(event)
561
560
  handle_event(event, {
@@ -567,7 +566,7 @@ module AWS
567
566
  # Handler for the `:StartChildWorkflowExecutionInitiated` event.
568
567
  #
569
568
  # @param [Object] event
570
- # The event to process
569
+ # The event to process.
571
570
  #
572
571
  def handle_start_child_workflow_execution_initiated(event)
573
572
  workflow_id = event.attributes[:workflow_id]
@@ -579,7 +578,7 @@ module AWS
579
578
  # Handler for the `:CancelTimerFailed` event.
580
579
  #
581
580
  # @param [Object] event
582
- # The event to process
581
+ # The event to process.
583
582
  #
584
583
  def handle_cancel_timer_failed(event)
585
584
  handle_event(event, {
@@ -588,10 +587,10 @@ module AWS
588
587
  })
589
588
  end
590
589
 
591
- # Handler for the `:WorkflowExecutionSignaled` event.
590
+ # Handler for the `WorkflowExecutionSignaled` event.
592
591
  #
593
592
  # @param [Object] event
594
- # The event to process
593
+ # The event to process.
595
594
  #
596
595
  def handle_workflow_execution_signaled(event)
597
596
  signal_name = event.attributes[:signal_name]
@@ -605,10 +604,10 @@ module AWS
605
604
  @workflow_async_scope.get_closest_containing_scope << t
606
605
  end
607
606
 
608
- # Processes decider events
607
+ # Processes decider events.
609
608
  #
610
609
  # @param [Object] event
611
- # The event to process
610
+ # The event to process.
612
611
  #
613
612
  def process_event(event)
614
613
  event_type_symbol = event.event_type.to_sym
@@ -656,7 +655,7 @@ module AWS
656
655
  # DecisionTaskStarted is taken care of at TODO
657
656
  end
658
657
 
659
- # @!visibility private
658
+ # @api private
660
659
  def event_loop(event)
661
660
  return if @completed
662
661
  begin