hermes_messenger_of_the_gods 2.2.0 → 2.3.2
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 +4 -4
- data/lib/hermes_messenger_of_the_gods/concerns/message.rb +2 -2
- data/lib/hermes_messenger_of_the_gods/configuration.rb +4 -1
- data/lib/hermes_messenger_of_the_gods/endpoints/sns.rb +7 -4
- data/lib/hermes_messenger_of_the_gods/endpoints/sqs.rb +24 -14
- data/lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb +5 -1
- data/lib/hermes_messenger_of_the_gods/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45e46de302befb016769708d8ec0e3d500e1dc3d83f3c2759eb37e089df3f54d
|
4
|
+
data.tar.gz: f678ce9af82af7750fce178b117c2e4fcc79a133d1e79d132d1ec9e29b9428c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4bfd0c75c08192c83866e6a5c744b9b4670a84858c93afcf24aab0af4ab8edb2ac2f7de7dc2d4dadc02eb27e906b34293a16d1fa0e5a75c35a35ba79618f30c
|
7
|
+
data.tar.gz: 64c3bdc04eaeebdfa0a73c0f7c0654f2274c2ef9a8f44f145b868b7805be971303a6b5e4df24b89522c7e348788dee68c67634e153b854820d93a72ae431a5c2
|
@@ -61,7 +61,7 @@ module HermesMessengerOfTheGods
|
|
61
61
|
endpoints.collect do |ep_name, endpoint|
|
62
62
|
next if targeted_endpoints && !targeted_endpoints.include?(ep_name)
|
63
63
|
|
64
|
-
|
64
|
+
begin
|
65
65
|
endpoint.dispatch!(self, endpoint_args) unless HermesMessengerOfTheGods.config.stub_dispatch
|
66
66
|
register_success(ep_name, endpoint.result)
|
67
67
|
rescue StandardError => e
|
@@ -70,7 +70,7 @@ module HermesMessengerOfTheGods
|
|
70
70
|
ensure
|
71
71
|
endpoint.teardown
|
72
72
|
end
|
73
|
-
end
|
73
|
+
end
|
74
74
|
|
75
75
|
unless dispatch_errors.empty?
|
76
76
|
klass = if successes.empty?
|
@@ -10,7 +10,7 @@ module HermesMessengerOfTheGods
|
|
10
10
|
if instance_variable_defined?("@#{meth}")
|
11
11
|
instance_variable_get("@#{meth}")
|
12
12
|
else
|
13
|
-
instance_variable_set("@#{meth}", default)
|
13
|
+
instance_variable_set("@#{meth}", default.respond_to?(:call) ? default.call() : default)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -25,5 +25,8 @@ module HermesMessengerOfTheGods
|
|
25
25
|
attr_accessor_with_default :stub_dispatch, false
|
26
26
|
|
27
27
|
attr_accessor_with_default :kill_on_consecutive_failures, false
|
28
|
+
|
29
|
+
attr_accessor_with_default :sqs_client, -> { Aws::SQS::Client.new }
|
30
|
+
attr_accessor_with_default :sns_client, -> { Aws::SNS::Client.new }
|
28
31
|
end
|
29
32
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'aws-sdk-sns'
|
2
4
|
require 'json'
|
3
5
|
|
@@ -5,15 +7,16 @@ module HermesMessengerOfTheGods
|
|
5
7
|
module Endpoints
|
6
8
|
class Sns < Base
|
7
9
|
def sns_topic
|
8
|
-
@sns_topic ||= Aws::SNS::Topic.new(
|
9
|
-
|
10
|
-
|
10
|
+
@sns_topic ||= Aws::SNS::Topic.new(endpoint,
|
11
|
+
{
|
12
|
+
client: HermesMessengerOfTheGods.configuration.sns_client
|
13
|
+
}.merge(options[:client_options] || {}))
|
11
14
|
end
|
12
15
|
|
13
16
|
def transmit(message, raw_message, dispatch_options = {})
|
14
17
|
pub_opts = fetch_option(:publish_options, raw_message) || {}
|
15
18
|
|
16
|
-
message = JSON.dump(message) if
|
19
|
+
message = JSON.dump(message) if options[:jsonify]
|
17
20
|
sns_topic.publish(pub_opts.merge(dispatch_options, message: message))
|
18
21
|
end
|
19
22
|
end
|
@@ -14,9 +14,14 @@ module HermesMessengerOfTheGods
|
|
14
14
|
super
|
15
15
|
@message_mux = Monitor.new
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def poller
|
19
|
-
@poller ||= Aws::SQS::QueuePoller.new(
|
19
|
+
@poller ||= Aws::SQS::QueuePoller.new(
|
20
|
+
endpoint,
|
21
|
+
{
|
22
|
+
client: HermesMessengerOfTheGods.configuration.sqs_client
|
23
|
+
}.merge(options[:client_options] || {})
|
24
|
+
)
|
20
25
|
end
|
21
26
|
|
22
27
|
def inflight_messages
|
@@ -33,11 +38,12 @@ module HermesMessengerOfTheGods
|
|
33
38
|
|
34
39
|
# Basic Shutdown behavior:
|
35
40
|
# 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
|
41
|
+
# Reset visbility timeout to all un-executed messages (from current message to end of array) to 0 so they move
|
37
42
|
# to other works
|
38
43
|
#
|
39
44
|
# Break from polling
|
40
45
|
def shutdown!
|
46
|
+
warn 'Shutdown command received'
|
41
47
|
@shutdown = true
|
42
48
|
end
|
43
49
|
|
@@ -46,7 +52,7 @@ module HermesMessengerOfTheGods
|
|
46
52
|
end
|
47
53
|
|
48
54
|
def work_off(&blk)
|
49
|
-
poller.before_request { |
|
55
|
+
poller.before_request { |_stats| throw :stop_polling if shutting_down? }
|
50
56
|
|
51
57
|
poller.poll(poll_options) do |messages, _stats|
|
52
58
|
self.inflight_messages = messages = Array.wrap(messages)
|
@@ -60,11 +66,12 @@ module HermesMessengerOfTheGods
|
|
60
66
|
# Work message returns true if the messager should be considered successful
|
61
67
|
shutting_down? ? :shutdown : work_message(msg, &blk)
|
62
68
|
end
|
63
|
-
|
69
|
+
|
64
70
|
poller.delete_messages(completion_results[true]) unless completion_results.fetch(true, []).empty?
|
65
71
|
# Messages skipped due to shutdowns get their visibility set back to 0 so they restart
|
66
72
|
# 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,
|
73
|
+
set_message_visibility(completion_results[:shutdown], 0) unless completion_results.fetch(:shutdown,
|
74
|
+
[]).empty?
|
68
75
|
end
|
69
76
|
end
|
70
77
|
end
|
@@ -84,7 +91,12 @@ module HermesMessengerOfTheGods
|
|
84
91
|
end
|
85
92
|
|
86
93
|
def queue
|
87
|
-
@queue ||= Aws::SQS::Queue.new(
|
94
|
+
@queue ||= Aws::SQS::Queue.new(
|
95
|
+
endpoint,
|
96
|
+
{
|
97
|
+
client: HermesMessengerOfTheGods.configuration.sqs_client
|
98
|
+
}.merge(options[:client_options] || {})
|
99
|
+
)
|
88
100
|
end
|
89
101
|
|
90
102
|
def queue_data
|
@@ -94,9 +106,9 @@ module HermesMessengerOfTheGods
|
|
94
106
|
def has_pending_work?
|
95
107
|
data = queue_data.attributes
|
96
108
|
|
97
|
-
approximate_pending_messages = data[
|
98
|
-
|
99
|
-
|
109
|
+
approximate_pending_messages = data['ApproximateNumberOfMessages'].to_i -
|
110
|
+
data['ApproximateNumberOfMessagesNotVisible'].to_i -
|
111
|
+
data['ApproximateNumberOfMessagesDelayed'].to_i
|
100
112
|
|
101
113
|
# Just in case the math is off
|
102
114
|
approximate_pending_messages > 0
|
@@ -132,16 +144,14 @@ module HermesMessengerOfTheGods
|
|
132
144
|
set_message_visibility(inflight_messages, new_time)
|
133
145
|
sleep VISIBILITY_EXTEND_FREQUENCY
|
134
146
|
rescue StandardError => e
|
135
|
-
|
136
|
-
|
147
|
+
warn 'Error received trying to extend visibility'
|
148
|
+
warn e.message
|
137
149
|
|
138
150
|
raise
|
139
151
|
end
|
140
152
|
end
|
141
153
|
end
|
142
154
|
|
143
|
-
private
|
144
|
-
|
145
155
|
def set_message_visibility(messages, new_time)
|
146
156
|
queue.change_message_visibility_batch(
|
147
157
|
entries: messages.collect do |message|
|
@@ -15,6 +15,8 @@ module HermesMessengerOfTheGods
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
attr_accessor :on_receive
|
19
|
+
|
18
20
|
def received
|
19
21
|
self.class.received[endpoint]
|
20
22
|
end
|
@@ -29,7 +31,9 @@ module HermesMessengerOfTheGods
|
|
29
31
|
|
30
32
|
def do_transmit(msg, opts, raw_message = {})
|
31
33
|
pub_opts = fetch_option(:publish_options, raw_message) || {}
|
32
|
-
|
34
|
+
new_msg = { message: msg, options: opts.merge(pub_opts) }
|
35
|
+
received << new_msg
|
36
|
+
on_receive.call(new_msg) if on_receive
|
33
37
|
"Recorded msg ##{self.class.received[endpoint].length} for #{endpoint}"
|
34
38
|
end
|
35
39
|
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.2
|
4
|
+
version: 2.3.2
|
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:
|
12
|
+
date: 2022-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|