ntswf 2.2.2 → 2.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e76f1bb295ab949307ec10635edd173860a203ce
4
- data.tar.gz: 622559c42321d9b560df16f4739bbbabf4d600a8
3
+ metadata.gz: eaca998680d15e5774111c72cec550bf007f4b3b
4
+ data.tar.gz: 85ef085caee9057b275ac3dbea0283f7bc4a3226
5
5
  SHA512:
6
- metadata.gz: 679c86ad4a385e8998d4e7cfb9977daf87d5e0d6bc2c49187f766c3a3755b3dddf834dcb2918b400362827d50d77926b65f6baaa4eebd8db58b344fb7937a962
7
- data.tar.gz: 9a8dbf9d473f27a162a90d3f8930a6bd512609ce8cc8bb703951df1bec9796af4b9d35efcadae84d1bc0cf2f763099980af2467d1c3615aa948a2ffb13b1dae1
6
+ metadata.gz: d1c424625e79cf8b2dd61467b75653a339f64d892d0e117e16f28c643c5ee6ca8e33f6db15d04b94ded33a429602e471810ca58a2b973d96dc62a1e821ba2992
7
+ data.tar.gz: 0d5a73d6197c85cfec21f61fa26e372daff066fb2b663e57eaba14bd8b6ea40b8894ff050cd752e7dc5ddb26ce0e08779a40d7d08dd0c04e269791e96d37cb7c
data/README.md CHANGED
@@ -39,7 +39,7 @@ Ntswf.create(:decision_worker, config).process_decisions
39
39
  ```
40
40
  config = {domain: 'my_domain', unit: 'my_worker'} # ...
41
41
  worker = Ntswf.create(:activity_worker, config)
42
- worker.on_task ->(task) { Ntswf.result task.params['my_param'] }
42
+ worker.on_activity ->(task) { {outcome: task.params['my_param']} }
43
43
  worker.process_activities
44
44
  ```
45
45
 
@@ -47,11 +47,6 @@ module Ntswf
47
47
 
48
48
  protected
49
49
 
50
- def activity_task_list
51
- activity_task_lists[default_unit] or raise Errors::InvalidArgument.new(
52
- "Missing activity task list configuration for default unit '#{default_unit}'")
53
- end
54
-
55
50
  def process_single_task(activity_task)
56
51
  returned_hash = @task_callback.call(describe(activity_task)) if @task_callback
57
52
  process_returned_hash(activity_task, returned_hash)
@@ -93,4 +88,4 @@ module Ntswf
93
88
  end
94
89
  end
95
90
  end
96
- end
91
+ end
@@ -6,16 +6,20 @@ module Ntswf
6
6
  module Base
7
7
  # @param config [Hash] A configuration with the following keys:
8
8
  # @option config [String] :access_key_id
9
- # AWS credential (deprecated, should use swf option)
9
+ # *deprecated:* AWS credential. Deprecated, use :swf instead.
10
10
  # @option config [Hash] :activity_task_lists
11
- # The task list names for activities as hash (see also *:unit*)
12
- # @option config [String] :decision_task_list The task list name for decisions
13
- # @option config [String] :domain The SWF domain name
11
+ # The task list names for activities per :unit.
12
+ # @option config [String] :decision_task_list
13
+ # *deprecated:* The task list name for decisions.
14
+ # Deprecated, use :decision_task_lists instead.
15
+ # @option config [Hash] :decision_task_lists
16
+ # The task list names for decisions per :unit.
17
+ # @option config [String] :domain The SWF domain name.
14
18
  # @option config [String] :execution_id_prefix
15
19
  # (value of :unit) Workflow ID prefix
16
- # (see {Client#start_execution}'s *:execution_id* for allowed values)
20
+ # (see {Client#start_execution}'s :execution_id for allowed values).
17
21
  # @option config [Numeric] :execution_version
18
- # Value allowing clients to reject future execution versions
22
+ # Value allowing clients to reject future execution versions.
19
23
  # @option config [String] :identity_suffix
20
24
  # When polling for a task, the suffix will be appended to the (default) identity
21
25
  # (<hostname>:<pid>), delimited by a ":".
@@ -25,17 +29,16 @@ module Ntswf
25
29
  # A random ID is stored at the given path, and prepended to task list names and execution IDs.
26
30
  # @option config [String] :pidfile
27
31
  # A path receiving the current PID for looping methods. Causes exit, if
28
- # overwritten by another process. See {Worker#in_subprocess}
32
+ # overwritten by another process. See {Worker#in_subprocess}.
29
33
  # @option config [String] :secret_access_key
30
- # AWS credential (deprecated, should use swf option)
31
- # @option config [Numeric] :subprocess_retries (0) see {Worker#in_subprocess}
34
+ # *deprecated:* AWS credential. Deprecated, use :swf instead.
35
+ # @option config [Numeric] :subprocess_retries (0) See {Worker#in_subprocess}.
32
36
  # @option config [AWS::SimpleWorkflow] :swf
33
- # AWS simple workflow object (created e.g. with AWS::SimpleWorkflow.new)
34
- # @option config [String] :unit This worker/client's activity task list key
35
- # @raise [Errors::InvalidArgument] If a task list name is invalid
37
+ # AWS simple workflow object (created e.g. with AWS::SimpleWorkflow.new).
38
+ # @option config [String] :unit This worker/client's activity task list key.
39
+ # @raise [Errors::InvalidArgument] If a task list name is invalid.
36
40
  def configure(config)
37
41
  @config = OpenStruct.new(config)
38
- autocomplete_task_list_names!
39
42
  raise_if_invalid_task_list
40
43
  end
41
44
 
@@ -74,12 +77,24 @@ module Ntswf
74
77
  end
75
78
 
76
79
  def activity_task_lists
77
- @config.activity_task_lists
80
+ autocompleted_activity_task_lists || {}
78
81
  end
79
82
 
80
- def decision_task_list
81
- @config.decision_task_list or raise Errors::InvalidArgument.new(
82
- "Missing decision task list configuration")
83
+ def activity_task_list(unit: nil)
84
+ unit ||= default_unit
85
+ activity_task_lists[unit] or raise Errors::InvalidArgument.new(
86
+ "Missing activity task list configuration for unit '#{unit}'")
87
+ end
88
+
89
+ def decision_task_lists
90
+ autocompleted_decision_task_lists || fallback_decision_task_lists
91
+ end
92
+
93
+ def decision_task_list(unit: nil)
94
+ unit ||= default_unit
95
+ decision_task_lists[unit] || decision_task_lists[default_unit] or
96
+ raise Errors::InvalidArgument.new(
97
+ "Missing decision task list configuration for unit '#{unit}'")
83
98
  end
84
99
 
85
100
  def default_unit
@@ -131,8 +146,7 @@ module Ntswf
131
146
  end
132
147
 
133
148
  def raise_if_invalid_task_list
134
- atl_values = activity_task_lists.values if activity_task_lists
135
- [*atl_values, *@config.decision_task_list].each do |task_list|
149
+ all_task_list_names.each do |task_list|
136
150
  if task_list.include?(separator)
137
151
  raise Errors::InvalidArgument.new(
138
152
  "Invalid config '#{task_list}': Separator '#{separator}' is reserved for internal use.")
@@ -144,13 +158,26 @@ module Ntswf
144
158
  end
145
159
  end
146
160
 
147
- def autocomplete_task_list_names!
148
- @config.decision_task_list = autocomplete(@config.decision_task_list, "master-dtl")
149
- if @config.activity_task_lists
150
- @config.activity_task_lists.each do |key, value|
151
- @config.activity_task_lists[key] = autocomplete(value, "#{key}-atl")
152
- end
153
- end
161
+ def all_task_list_names
162
+ [*activity_task_lists.values, *decision_task_lists.values, *@config.decision_task_list]
163
+ end
164
+
165
+ def autocompleted_activity_task_lists
166
+ autocompleted_task_lists(@config.activity_task_lists, :atl)
167
+ end
168
+
169
+ def autocompleted_decision_task_lists
170
+ autocompleted_task_lists(@config.decision_task_lists, :dtl)
171
+ end
172
+
173
+ def autocompleted_task_lists(raw_task_lists, suffix)
174
+ Hash(raw_task_lists).map do |unit, name|
175
+ {unit => autocomplete(name, "#{unit}-#{suffix}")}
176
+ end.reduce(:merge)
177
+ end
178
+
179
+ def fallback_decision_task_lists
180
+ {default_unit => autocomplete(@config.decision_task_list, "master-dtl")}
154
181
  end
155
182
 
156
183
  def autocomplete(value, fallback)
@@ -10,6 +10,9 @@ module Ntswf
10
10
  # The options configure the control flow of the task.
11
11
  # Excluding *:execution_id* they will be stored in the *input* argument of the task as JSON.
12
12
  # @param options [Hash] The task's options. Keys with special meaning:
13
+ # @option options [String] :activity_task_list
14
+ # The activity task list that this execution's activity tasks are routed to.
15
+ # Should be +nil+ if the execution is not bound to a specific activity task list.
13
16
  # @option options [String] :execution_id
14
17
  # Mandatory workflow ID suffix, allowed IDs are documented at docs.amazonwebservices.com
15
18
  # (WorkflowId Property)
@@ -21,7 +24,8 @@ module Ntswf
21
24
  # @option options [Array<String>] :tag_list
22
25
  # Additional strings that will be added to to the tag list of the workflow execution.
23
26
  # @option options [String] :unit
24
- # The executing unit's key, a corresponding activity task list must be configured
27
+ # The executing unit's key.
28
+ # Corresponding task lists must be configured. See {Base#configure}.
25
29
  # @option options [Numeric] :version
26
30
  # Optional minimum version of the client. The task may be rescheduled by older clients.
27
31
  # @return [Hash]
@@ -67,12 +71,13 @@ module Ntswf
67
71
 
68
72
  def start_swf_workflow_execution(options)
69
73
  execution_id = options.delete(:execution_id)
74
+ unit = options[:unit]
70
75
  workflow_type.start_execution(
71
76
  child_policy: :terminate,
72
77
  execution_start_to_close_timeout: 48 * 3600,
73
78
  input: options.to_json,
74
- tag_list: [options[:unit].to_s, options[:name].to_s] + Array(options[:tag_list]),
75
- task_list: decision_task_list,
79
+ tag_list: [unit.to_s, options[:name].to_s] + Array(options[:tag_list]),
80
+ task_list: decision_task_list(unit: unit),
76
81
  task_start_to_close_timeout: 10 * 60,
77
82
  workflow_id: workflow_id(execution_id_prefix, execution_id),
78
83
  )
@@ -94,10 +94,8 @@ module Ntswf
94
94
  def schedule(task, data_providing_event)
95
95
  input = data_providing_event.attributes.input
96
96
  options = parse_input(input)
97
- app_in_charge = options['unit'] || guess_app_from(data_providing_event)
98
- task_list = activity_task_lists[app_in_charge]
99
- raise Errors::InvalidArgument.new(
100
- "Missing activity task list config for #{app_in_charge.inspect}") unless task_list
97
+ task_list = options['activity_task_list'] ||
98
+ activity_task_list(unit: options['unit'] || guess_app_from(data_providing_event))
101
99
 
102
100
  task.schedule_activity_task(activity_type, {
103
101
  heartbeat_timeout: :none,
@@ -132,4 +130,4 @@ module Ntswf
132
130
  data_providing_event.workflow_execution.workflow_type.name[/\w+/]
133
131
  end
134
132
  end
135
- end
133
+ end
@@ -66,4 +66,4 @@ module Ntswf
66
66
  end
67
67
 
68
68
  end
69
- end
69
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntswf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Infopark AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-v1
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: 1.9.3
84
+ version: 2.0.0
85
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.4.5
92
+ rubygems_version: 2.4.5.1
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Not That Simple Workflow