hermes_messenger_of_the_gods 2.1.1 → 2.2.0

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: c9fb8caf1a8299a378495d5f33f4be6e226725ceb3d9a2bfca2ee301ddfa74b2
4
- data.tar.gz: 20ae2dedfc73f959bbb8705c398a293bb105d4f3362e1b33c62a0bf00705c7e4
3
+ metadata.gz: eb594dd4aa42c53e4bb9f412dc0870f4de4361843007653f0b00f27d9dabb24b
4
+ data.tar.gz: 745bb17e713aa8271933429db47198a054f32d494257777b7064227e51ba8850
5
5
  SHA512:
6
- metadata.gz: 82d1ef250df05d7630816d9c02fb1cc35024d101d82263b213762336110daaef10cc33d6b84ced72eb3a712981e75ffc1ad5aa0327081a8c46ebfc1cd60ffb86
7
- data.tar.gz: 0b618c1608e636d4afb210fe3cafa8bd0786a8e0c74da0f14b5ad10067c0b6293f2b495d283c9c016abcc2fb63b3dfbeb56d69d5b8fac28405e108eb30f3d66d
6
+ metadata.gz: 161da7750d743c04bdc0a56be97fea405adeabe0ebb20bd42bd1c1afcebc08fec176309dd73126ca284b389a53ae489e5a8773583a20744b6a4da5a9145643ad
7
+ data.tar.gz: 477eb8aeb67d6d4011bf59f1fcadb0b9f0f2da98ec9a2b551e420e14f6197185a97e25912f2f6c6dfa1ce4d6f3b6f7709e76f3cb4bc864550b7649dfe9e0379e
@@ -31,6 +31,7 @@ jobs:
31
31
  COVERALLS_NOISY=true bundle exec rspec --color --format documentation;"
32
32
 
33
33
  - name: Push Coveralls
34
+ continue-on-error: true
34
35
  env:
35
36
  TOKEN: ${{ secrets.COVERALLS_TOKEN }}
36
37
  working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .bundle
13
+ *.gem
@@ -32,6 +32,9 @@ module HermesMessengerOfTheGods
32
32
  def work_off
33
33
  WorkerStatusServer.start!(worker: self) if health_check_enabled?
34
34
 
35
+ trap(:TERM) { endpoint.shutdown! }
36
+ trap(:INT) { endpoint.shutdown! }
37
+
35
38
  instrument(:starting)
36
39
  self.consecutive_failures = 0
37
40
  endpoint.work_off do |job, original_message|
@@ -10,21 +10,61 @@ module HermesMessengerOfTheGods
10
10
  VISIBILITY_EXTEND_DURATION = 120
11
11
  VISIBILITY_EXTEND_FREQUENCY = 60
12
12
 
13
+ def initialize(*args)
14
+ super
15
+ @message_mux = Monitor.new
16
+ end
17
+
13
18
  def poller
14
19
  @poller ||= Aws::SQS::QueuePoller.new(endpoint)
15
20
  end
16
21
 
22
+ def inflight_messages
23
+ @message_mux.synchronize { @inflight_messages ||= [] }
24
+ end
25
+
26
+ def inflight_messages=(val)
27
+ @message_mux.synchronize { @inflight_messages = val }
28
+ end
29
+
30
+ def shutting_down?
31
+ @shutdown || false
32
+ end
33
+
34
+ # Basic Shutdown behavior:
35
+ # Allow in-progress message to finish working.
36
+ # Reset visbility timeout to all un-executed messages (from current message to end of array) to 0 so they move
37
+ # to other works
38
+ #
39
+ # Break from polling
40
+ def shutdown!
41
+ @shutdown = true
42
+ end
43
+
17
44
  def poll_options
18
45
  (options[:poll_options] || {}).merge(skip_delete: true)
19
46
  end
20
47
 
21
48
  def work_off(&blk)
22
- poller.poll(poll_options) do |messages, _stats|
23
- messages = Array.wrap(messages)
49
+ poller.before_request { |stats| throw :stop_polling if shutting_down? }
24
50
 
25
- working_messages(messages) do
26
- completed = messages.select { |msg| work_message(msg, &blk) }
27
- poller.delete_messages(completed) unless completed.empty?
51
+ poller.poll(poll_options) do |messages, _stats|
52
+ self.inflight_messages = messages = Array.wrap(messages)
53
+
54
+ working_messages do
55
+ completion_results = messages.group_by do |msg|
56
+ # We return false if we are shutting down so the messages are not deleted.
57
+ # It is also possible that this process has already releases these SQS messages
58
+ # back in to the queue so they may be picked up by another process.
59
+ #
60
+ # Work message returns true if the messager should be considered successful
61
+ shutting_down? ? :shutdown : work_message(msg, &blk)
62
+ end
63
+
64
+ poller.delete_messages(completion_results[true]) unless completion_results.fetch(true, []).empty?
65
+ # Messages skipped due to shutdowns get their visibility set back to 0 so they restart
66
+ # normal failed jobs will be left in queue until their visibility timeout expires to indicate a backoff
67
+ set_message_visibility(completion_results[:shutdown], 0) unless completion_results.fetch(:shutdown, []).empty?
28
68
  end
29
69
  end
30
70
  end
@@ -77,29 +117,19 @@ module HermesMessengerOfTheGods
77
117
  message_body
78
118
  end
79
119
 
80
- def working_messages(messages)
81
- thread = start_visibility_update_thread(messages)
82
-
120
+ def working_messages
121
+ thread = start_visibility_update_thread
83
122
  yield
84
123
  ensure
85
124
  thread&.terminate
86
125
  end
87
126
 
88
- def start_visibility_update_thread(messages)
127
+ def start_visibility_update_thread
89
128
  start_work_time = Time.now
90
129
  Thread.new do
91
130
  loop do
92
131
  new_time = (Time.now - start_work_time) + VISIBILITY_EXTEND_DURATION
93
- queue.change_message_visibility_batch(
94
- entries: messages.collect do |message|
95
- {
96
- id: SecureRandom.uuid,
97
- receipt_handle: message.receipt_handle,
98
- visibility_timeout: new_time
99
- }
100
- end
101
- )
102
-
132
+ set_message_visibility(inflight_messages, new_time)
103
133
  sleep VISIBILITY_EXTEND_FREQUENCY
104
134
  rescue StandardError => e
105
135
  STDERR.puts 'Error received trying to extend visibility'
@@ -109,6 +139,20 @@ module HermesMessengerOfTheGods
109
139
  end
110
140
  end
111
141
  end
142
+
143
+ private
144
+
145
+ def set_message_visibility(messages, new_time)
146
+ queue.change_message_visibility_batch(
147
+ entries: messages.collect do |message|
148
+ {
149
+ id: SecureRandom.uuid,
150
+ receipt_handle: message.receipt_handle,
151
+ visibility_timeout: new_time
152
+ }
153
+ end
154
+ )
155
+ end
112
156
  end
113
157
  end
114
158
  end
@@ -1,3 +1,3 @@
1
1
  module HermesMessengerOfTheGods
2
- VERSION = '2.1.1'
2
+ VERSION = '2.2.0'
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.1.1
4
+ version: 2.2.0
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: 2021-09-21 00:00:00.000000000 Z
12
+ date: 2021-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -226,8 +226,8 @@ files:
226
226
  - vendor/cache/activesupport-6.1.4.1.gem
227
227
  - vendor/cache/addressable-2.8.0.gem
228
228
  - vendor/cache/aws-eventstream-1.2.0.gem
229
- - vendor/cache/aws-partitions-1.503.0.gem
230
- - vendor/cache/aws-sdk-core-3.121.0.gem
229
+ - vendor/cache/aws-partitions-1.509.0.gem
230
+ - vendor/cache/aws-sdk-core-3.121.1.gem
231
231
  - vendor/cache/aws-sdk-sns-1.45.0.gem
232
232
  - vendor/cache/aws-sdk-sqs-1.44.0.gem
233
233
  - vendor/cache/aws-sigv4-1.4.0.gem
@@ -238,9 +238,11 @@ files:
238
238
  - vendor/cache/crack-0.4.5.gem
239
239
  - vendor/cache/diff-lcs-1.4.4.gem
240
240
  - vendor/cache/docile-1.4.0.gem
241
- - vendor/cache/google-protobuf-3.17.3-x86_64-linux.gem
242
- - vendor/cache/googleapis-common-protos-types-1.1.0.gem
243
- - vendor/cache/grpc-1.38.0-x86_64-linux.gem
241
+ - vendor/cache/google-protobuf-3.18.0-universal-darwin.gem
242
+ - vendor/cache/google-protobuf-3.18.0-x86_64-linux.gem
243
+ - vendor/cache/googleapis-common-protos-types-1.2.0.gem
244
+ - vendor/cache/grpc-1.40.0-universal-darwin.gem
245
+ - vendor/cache/grpc-1.40.0-x86_64-linux.gem
244
246
  - vendor/cache/hashdiff-1.0.1.gem
245
247
  - vendor/cache/i18n-1.8.10.gem
246
248
  - vendor/cache/jmespath-1.4.0.gem
@@ -287,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
289
  - !ruby/object:Gem::Version
288
290
  version: '0'
289
291
  requirements: []
290
- rubygems_version: 3.2.27
292
+ rubygems_version: 3.2.22
291
293
  signing_key:
292
294
  specification_version: 4
293
295
  summary: Create and receive messages like a god!
Binary file