ntswf 2.0.3 → 2.0.4

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.
@@ -39,22 +39,29 @@ module Ntswf
39
39
  announce("polling for activity task #{activity_task_list}")
40
40
  domain.activity_tasks.poll_for_single_task(activity_task_list) do |activity_task|
41
41
  announce("got activity task #{activity_task.activity_type.inspect} #{activity_task.input}")
42
- begin
43
- returned_hash = @task_callback.call(describe(activity_task)) if @task_callback
44
- process_returned_hash(activity_task, returned_hash)
45
- rescue => e
46
- notify(e, activity_type: activity_task.activity_type.inspect, input: activity_task.input)
47
- details = {
48
- error: e.message[0, 1000],
49
- exception: e.class.to_s[0, 1000],
50
- }
51
- activity_task.fail!(details: details.to_json, reason: 'Exception')
52
- end
42
+ process_single_task activity_task
53
43
  end
54
44
  end
55
45
 
56
46
  protected
57
47
 
48
+ def process_single_task(activity_task)
49
+ returned_hash = @task_callback.call(describe(activity_task)) if @task_callback
50
+ process_returned_hash(activity_task, returned_hash)
51
+ rescue => exception
52
+ fail_with_exception(activity_task, exception)
53
+ end
54
+
55
+ def fail_with_exception(activity_task, exception)
56
+ notify(exception, activity_type: activity_task.activity_type.inspect,
57
+ input: activity_task.input)
58
+ details = {
59
+ error: exception.message[0, 1000],
60
+ exception: exception.class.to_s[0, 1000],
61
+ }
62
+ activity_task.fail!(details: details.to_json, reason: 'Exception')
63
+ end
64
+
58
65
  def describe(activity_task)
59
66
  options = parse_input(activity_task.input)
60
67
  options.merge!(
data/lib/ntswf/base.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'aws'
2
2
  require 'ostruct'
3
+ require 'securerandom'
3
4
 
4
5
  module Ntswf
5
6
  module Base
@@ -16,10 +17,14 @@ module Ntswf
16
17
  # overwritten by another process. See {Worker#in_subprocess}
17
18
  # @option config [Numeric] :subprocess_retries (0) see {Worker#in_subprocess}
18
19
  # @option config [String] :secret_access_key AWS credential
20
+ # @option config [String] :task_list_suffix_file
21
+ # Development option.
22
+ # A random ID is stored at the given path, and appended to all task list names.
19
23
  # @option config [String] :unit This worker/client's activity task list key
20
24
  # @raise If a task list name is invalid
21
25
  def configure(config)
22
26
  @config = OpenStruct.new(config)
27
+ autocomplete_task_list_names!
23
28
  raise_if_invalid_task_list
24
29
  end
25
30
 
@@ -122,5 +127,26 @@ module Ntswf
122
127
  end
123
128
  end
124
129
  end
130
+
131
+ def autocomplete_task_list_names!
132
+ @config.decision_task_list = autocomplete(@config.decision_task_list, "master-dtl")
133
+ if @config.activity_task_lists
134
+ @config.activity_task_lists.each do |key, value|
135
+ @config.activity_task_lists[key] = autocomplete(value, "#{key}-atl")
136
+ end
137
+ end
138
+ end
139
+
140
+ def autocomplete(value, fallback)
141
+ value = fallback unless value.kind_of? String
142
+ "#{value}#{task_list_suffix}"
143
+ end
144
+
145
+ def task_list_suffix
146
+ file = @config.task_list_suffix_file
147
+ return "" unless file
148
+ File.write(file, SecureRandom.hex(9)) unless File.exist?(file)
149
+ @suffix ||= File.read(file)
150
+ end
125
151
  end
126
152
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntswf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-10 00:00:00.000000000 Z
12
+ date: 2014-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk