hermes_messenger_of_the_gods 2.3.3 → 2.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c3b23fec66c0a1e150672c00be3bff512ae95edb8159c5f4d43b83198df9f0a
4
- data.tar.gz: 1bfa70e4c8e9bb56c0d3e27e625239e03eeb16567119eee90f7c55ea9043146e
3
+ metadata.gz: 306982bf98f79ad4a92c01b8cbf7ba68acf8173904d3adc8fde204b746c8a2a7
4
+ data.tar.gz: efd5cca6cced4209b4c663d77e6ad4d26e80c084b9de29422f691d6f814d257a
5
5
  SHA512:
6
- metadata.gz: b32b27892082385431cc44a19f7552a6d1b788a55067576713ad9e9cff7ff147ea3ac693de7134730531af75285e4d1a62cceafe899a1857a85f51de3fc620b9
7
- data.tar.gz: 1f46c52269a3c7df4d422813dfba7c6c391772cc9b3e3b64da9a79f9c1aeaa30561612d2ec5558d155953588a5a7fc39bcc40164f39565ed913566b570ee7615
6
+ metadata.gz: 3b12f3abc2b2cfb6da3a4d1d0991cecd42d76ebb6c9cb4d4625abbb915112b3bb07860842ad318a55de9b8a627b71c3be7ed5d49056c4b969765da8a637ac84e
7
+ data.tar.gz: ceb1f94c06e19be4f9b5ab630b78ea6e723b63ca8ad4d8d74f2168c4ecfef2c60207e1ca324b09474166a960b16c824510449de78f1d73bba519f075ce63b37d
@@ -14,11 +14,7 @@ module HermesMessengerOfTheGods
14
14
  include ActiveModel::Model
15
15
  include HermesMessengerOfTheGods::Concerns::Base
16
16
 
17
- attr_accessor :targeted_endpoints
18
-
19
- def original_message
20
- @original_message
21
- end
17
+ attr_accessor :targeted_endpoints, :original_message, :source_endpoint
22
18
 
23
19
  def initialize(options = {})
24
20
  @monitor = Monitor.new
@@ -54,6 +50,15 @@ module HermesMessengerOfTheGods
54
50
  end
55
51
  end
56
52
 
53
+ def retry_at(future_time_or_seconds_in_future)
54
+ raise 'unable to set visiblity' if source_endpoint.nil? || original_message.nil?
55
+ unless source_endpoint.respond_to?(:set_reexecution_time)
56
+ raise "endpoint type doesn't support setting execution time"
57
+ end
58
+
59
+ source_endpoint.set_reexecution_time(original_message, future_time_or_seconds_in_future)
60
+ end
61
+
57
62
  def dispatch!(endpoint_args: {})
58
63
  run_callbacks :dispatch do
59
64
  validate!
@@ -65,7 +70,7 @@ module HermesMessengerOfTheGods
65
70
  endpoint.dispatch!(self, endpoint_args) unless HermesMessengerOfTheGods.config.stub_dispatch
66
71
  register_success(ep_name, endpoint.result)
67
72
  rescue StandardError => e
68
- error(e)
73
+ say_error(e)
69
74
  register_failure(ep_name, e)
70
75
  ensure
71
76
  endpoint.teardown
@@ -155,13 +160,13 @@ module HermesMessengerOfTheGods
155
160
  _circuit_breaker_errors
156
161
  end
157
162
 
158
-
159
163
  def max_consecutive_failures
160
164
  _max_consecutive_failures
161
165
  end
162
166
 
163
167
  def max_consecutive_failures=(val)
164
168
  raise 'Expected an Integer' unless val.is_a?(Integer) || val.is_a?(NilClass)
169
+
165
170
  self._max_consecutive_failures = val
166
171
  end
167
172
 
@@ -169,12 +174,12 @@ module HermesMessengerOfTheGods
169
174
  val ||= {}
170
175
  raise 'Expected a hash' unless val.is_a?(Hash)
171
176
 
172
- val.each do |err, actions|
177
+ val.each do |err, _actions|
173
178
  val[err][:sleep] ||= 0
174
179
  val[err][:fatal] ||= false
175
180
  end
176
181
 
177
- val.each do |err, actions|
182
+ val.each do |_err, actions|
178
183
  raise ':sleep must be a number' unless actions[:sleep].is_a?(Numeric)
179
184
  raise ':fatal must be a boolean' unless [true, false].include?(actions[:fatal])
180
185
  end
@@ -183,9 +188,7 @@ module HermesMessengerOfTheGods
183
188
  end
184
189
 
185
190
  def endpoints=(val)
186
- unless val.is_a?(Hash)
187
- raise 'Endpoints expects a hash {endpoint_name: endpoint_handler}'
188
- end
191
+ raise 'Endpoints expects a hash {endpoint_name: endpoint_handler}' unless val.is_a?(Hash)
189
192
 
190
193
  self._endpoints = val
191
194
  end
@@ -40,7 +40,9 @@ module HermesMessengerOfTheGods
40
40
  endpoint.work_off do |job, original_message|
41
41
  self.last_task_performed = Time.now
42
42
 
43
- built_job = deserialize(job, original_message)
43
+ built_job = deserialize(job)
44
+ built_job.original_message = original_message
45
+ built_job.source_endpoint = endpoint
44
46
  instrument(:starting_job, job: built_job)
45
47
  built_job.validate! if built_job.respond_to?(:validate!)
46
48
  run_job(built_job)
@@ -99,12 +101,10 @@ module HermesMessengerOfTheGods
99
101
  self.consecutive_failures += 1
100
102
  end
101
103
 
102
- def deserialize(raw_job, original_message)
104
+ def deserialize(raw_job)
103
105
  instrument(:deserialization, job: raw_job) do
104
106
  deserialize_method = self.class.deserialize_method || :from_message
105
- self.class.deserialize_with.send(deserialize_method, raw_job).tap do |obj|
106
- obj.instance_variable_set :@original_message, original_message
107
- end
107
+ self.class.deserialize_with.send(deserialize_method, raw_job)
108
108
  end
109
109
  end
110
110
 
@@ -13,6 +13,7 @@ module HermesMessengerOfTheGods
13
13
  def initialize(*args)
14
14
  super
15
15
  @message_mux = Monitor.new
16
+ @work_start_time_mux = Monitor.new
16
17
  end
17
18
 
18
19
  def poller
@@ -24,6 +25,14 @@ module HermesMessengerOfTheGods
24
25
  )
25
26
  end
26
27
 
28
+ def work_start_time
29
+ @work_start_time_mux.synchronize { @work_start_time }
30
+ end
31
+
32
+ def reset_work_start_time!
33
+ @work_start_time_mux.synchronize { @work_start_time = Time.now }
34
+ end
35
+
27
36
  def inflight_messages
28
37
  @message_mux.synchronize { @inflight_messages ||= [] }
29
38
  end
@@ -67,15 +76,35 @@ module HermesMessengerOfTheGods
67
76
  shutting_down? ? :shutdown : work_message(msg, &blk)
68
77
  end
69
78
 
70
- poller.delete_messages(completion_results[true]) unless completion_results.fetch(true, []).empty?
79
+ unless completion_results.fetch(true, []).empty?
80
+ poller.delete_messages(completion_results[true] & inflight_messages)
81
+ end
71
82
  # Messages skipped due to shutdowns get their visibility set back to 0 so they restart
72
83
  # normal failed jobs will be left in queue until their visibility timeout expires to indicate a backoff
73
- set_message_visibility(completion_results[:shutdown], 0) unless completion_results.fetch(:shutdown,
74
- []).empty?
84
+ unless completion_results.fetch(:shutdown, []).empty?
85
+ set_message_visibility(completion_results[:shutdown] & inflight_messages, 0)
86
+ end
75
87
  end
76
88
  end
77
89
  end
78
90
 
91
+ def set_reexecution_time(message, duration_or_time)
92
+ # You can pass a time to re-run at or you can pass the seconds in the future to run at
93
+ extend_time = if duration_or_time.is_a?(Time)
94
+ duration_or_time - Time.now
95
+ else
96
+ duration_or_time
97
+ end
98
+
99
+ message_array = [message]
100
+
101
+ @message_mux.synchronize do
102
+ set_message_visibility(message_array, (Time.now - work_start_time) + extend_time)
103
+
104
+ @inflight_messages -= message_array
105
+ end
106
+ end
107
+
79
108
  def work_message(message)
80
109
  message_body = decode_message(message)
81
110
 
@@ -130,6 +159,7 @@ module HermesMessengerOfTheGods
130
159
  end
131
160
 
132
161
  def working_messages
162
+ reset_work_start_time!
133
163
  thread = start_visibility_update_thread
134
164
  yield
135
165
  ensure
@@ -137,10 +167,9 @@ module HermesMessengerOfTheGods
137
167
  end
138
168
 
139
169
  def start_visibility_update_thread
140
- start_work_time = Time.now
141
170
  Thread.new do
142
171
  loop do
143
- new_time = (Time.now - start_work_time) + VISIBILITY_EXTEND_DURATION
172
+ new_time = (Time.now - work_start_time) + VISIBILITY_EXTEND_DURATION
144
173
  set_message_visibility(inflight_messages, new_time)
145
174
  sleep VISIBILITY_EXTEND_FREQUENCY
146
175
  rescue StandardError => e
@@ -1,3 +1,3 @@
1
1
  module HermesMessengerOfTheGods
2
- VERSION = '2.3.3'
2
+ VERSION = '2.4.0.pre2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermes_messenger_of_the_gods
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 2.4.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Malinconico
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-07-08 00:00:00.000000000 Z
12
+ date: 2022-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -222,18 +222,10 @@ files:
222
222
  - lib/hermes_messenger_of_the_gods/testing/rspec_helpers.rb
223
223
  - lib/hermes_messenger_of_the_gods/version.rb
224
224
  - packageGems.sh
225
- - vendor/cache/activemodel-6.1.4.1.gem
226
- - vendor/cache/activesupport-6.1.4.1.gem
227
225
  - vendor/cache/addressable-2.8.0.gem
228
226
  - vendor/cache/aws-eventstream-1.2.0.gem
229
- - vendor/cache/aws-partitions-1.509.0.gem
230
- - vendor/cache/aws-sdk-core-3.121.1.gem
231
- - vendor/cache/aws-sdk-sns-1.45.0.gem
232
- - vendor/cache/aws-sdk-sqs-1.44.0.gem
233
- - vendor/cache/aws-sigv4-1.4.0.gem
234
227
  - vendor/cache/codeclimate-test-reporter-1.0.7.gem
235
228
  - vendor/cache/coderay-1.1.3.gem
236
- - vendor/cache/concurrent-ruby-1.1.9.gem
237
229
  - vendor/cache/coveralls_reborn-0.22.0.gem
238
230
  - vendor/cache/crack-0.4.5.gem
239
231
  - vendor/cache/diff-lcs-1.4.4.gem
@@ -244,11 +236,8 @@ files:
244
236
  - vendor/cache/grpc-1.40.0-universal-darwin.gem
245
237
  - vendor/cache/grpc-1.40.0-x86_64-linux.gem
246
238
  - vendor/cache/hashdiff-1.0.1.gem
247
- - vendor/cache/i18n-1.8.10.gem
248
- - vendor/cache/jmespath-1.4.0.gem
249
239
  - vendor/cache/memory_profiler-1.0.0.gem
250
240
  - vendor/cache/method_source-1.0.0.gem
251
- - vendor/cache/minitest-5.14.4.gem
252
241
  - vendor/cache/pry-0.14.1.gem
253
242
  - vendor/cache/public_suffix-4.0.6.gem
254
243
  - vendor/cache/rake-10.5.0.gem
@@ -267,9 +256,7 @@ files:
267
256
  - vendor/cache/thor-1.1.0.gem
268
257
  - vendor/cache/timecop-0.9.4.gem
269
258
  - vendor/cache/tins-1.29.1.gem
270
- - vendor/cache/tzinfo-2.0.4.gem
271
259
  - vendor/cache/webmock-3.14.0.gem
272
- - vendor/cache/zeitwerk-2.4.2.gem
273
260
  homepage:
274
261
  licenses: []
275
262
  metadata:
@@ -285,9 +272,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
285
272
  version: '0'
286
273
  required_rubygems_version: !ruby/object:Gem::Requirement
287
274
  requirements:
288
- - - ">="
275
+ - - ">"
289
276
  - !ruby/object:Gem::Version
290
- version: '0'
277
+ version: 1.3.1
291
278
  requirements: []
292
279
  rubygems_version: 3.2.22
293
280
  signing_key:
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file