sidekiq-amigo 1.13.0 → 1.14.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 +4 -4
- data/lib/amigo/retry.rb +23 -1
- data/lib/amigo/spec_helpers.rb +30 -10
- data/lib/amigo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 07551fc97532f4e4e819cb1f027b406df1c3144e98984cde26e90893420cf8fa
|
|
4
|
+
data.tar.gz: 67f0eb863e5d471897bc5c418c6ce8bdc4d118b54a6e135b32a97806159b91e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a8dfd02d648d865945e4491594c591c6304b015e1c7bcf51274c1126e4a7566ae9e9fab9a958b378a78d286d2889d84248396b497efa7502f68dd80b27ac5cd
|
|
7
|
+
data.tar.gz: 4a5391e68c465616da4cc95baaee0cbd676188a0ab62275ce4fcdd691260be10c0bdd7718fca26e72ef59f8c9657031341572ab3b141fc4f792240edac004de2
|
data/lib/amigo/retry.rb
CHANGED
|
@@ -59,6 +59,14 @@ module Amigo
|
|
|
59
59
|
# Raise this class, or a subclass of it, to:
|
|
60
60
|
# - Use +Retry+ exception semantics while the current attempt is <= +attempts+, or
|
|
61
61
|
# - Use +Die+ exception semantics if the current attempt is > +attempts+.
|
|
62
|
+
#
|
|
63
|
+
# Callers can provide a subclass with two methods that are looked for:
|
|
64
|
+
#
|
|
65
|
+
# If on_retry is defined, it is called with (worker instance, job hash).
|
|
66
|
+
# If on_retry returns +:skip+, do NOT retry (do not send to the retry set).
|
|
67
|
+
#
|
|
68
|
+
# If on_die is defined, it is called with (worker instance, job hash).
|
|
69
|
+
# If on_die returns +:skip+, do NOT send to the dead set.
|
|
62
70
|
class OrDie < Error
|
|
63
71
|
attr_reader :attempts, :interval_or_timestamp, :wrapped
|
|
64
72
|
|
|
@@ -99,13 +107,27 @@ module Amigo
|
|
|
99
107
|
end
|
|
100
108
|
|
|
101
109
|
def handle_retry(worker, job, e)
|
|
110
|
+
if e.respond_to?(:on_retry)
|
|
111
|
+
callback_result = e.on_retry(worker, job)
|
|
112
|
+
if callback_result == :skip
|
|
113
|
+
Sidekiq.logger.warn("skipping_retryset_schedule")
|
|
114
|
+
return
|
|
115
|
+
end
|
|
116
|
+
end
|
|
102
117
|
Sidekiq.logger.info("scheduling_retry")
|
|
103
118
|
job["error_class"] = e.class.to_s
|
|
104
119
|
job["error_message"] = e.to_s
|
|
105
120
|
self.amigo_retry_in(worker.class, job, e.interval_or_timestamp)
|
|
106
121
|
end
|
|
107
122
|
|
|
108
|
-
def handle_die(
|
|
123
|
+
def handle_die(worker, job, e)
|
|
124
|
+
if e.respond_to?(:on_die)
|
|
125
|
+
callback_result = e.on_die(worker, job)
|
|
126
|
+
if callback_result == :skip
|
|
127
|
+
Sidekiq.logger.warn("skipping_deadset_send")
|
|
128
|
+
return
|
|
129
|
+
end
|
|
130
|
+
end
|
|
109
131
|
Sidekiq.logger.warn("sending_to_deadset")
|
|
110
132
|
job["error_class"] = e.class.to_s
|
|
111
133
|
job["error_message"] = e.to_s
|
data/lib/amigo/spec_helpers.rb
CHANGED
|
@@ -72,7 +72,7 @@ module Amigo
|
|
|
72
72
|
true
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
def matches?(given_proc)
|
|
75
|
+
def matches?(given_proc, negative_expectation=false)
|
|
76
76
|
unless given_proc.respond_to?(:call)
|
|
77
77
|
warn "publish matcher used with non-proc object #{given_proc.inspect}"
|
|
78
78
|
return false
|
|
@@ -88,24 +88,41 @@ module Amigo
|
|
|
88
88
|
given_proc.call
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
-
self.match_expected_events
|
|
91
|
+
self.match_expected_events(negative_expectation)
|
|
92
92
|
|
|
93
93
|
return @error.nil? && @missing.empty?
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
+
# rubocop:disable Naming/PredicatePrefix
|
|
97
|
+
def does_not_match?(given_proc)
|
|
98
|
+
!matches?(given_proc, true)
|
|
99
|
+
end
|
|
100
|
+
# rubocop:enable Naming/PredicatePrefix
|
|
101
|
+
|
|
96
102
|
def on_publish_error(err)
|
|
97
103
|
@error = err
|
|
98
104
|
end
|
|
99
105
|
|
|
100
|
-
def match_expected_events
|
|
106
|
+
def match_expected_events(negative_expectation)
|
|
101
107
|
@expected_events.each do |expected_event, expected_payload|
|
|
108
|
+
if expected_event.nil? && !negative_expectation
|
|
109
|
+
RSpec::Expectations.configuration.false_positives_handler.call(
|
|
110
|
+
"Using the `publish` matcher without providing a specific " \
|
|
111
|
+
"event name risks false positives, since `publish` " \
|
|
112
|
+
"will match any event. Instead, provide the name " \
|
|
113
|
+
"of the event you are matching against."\
|
|
114
|
+
"This message can be suppressed by setting: " \
|
|
115
|
+
"`RSpec::Expectations.configuration.on_potential_false" \
|
|
116
|
+
"_positives = :nothing`",
|
|
117
|
+
)
|
|
118
|
+
end
|
|
102
119
|
match = @recorded_events.find do |recorded|
|
|
103
120
|
self.event_names_match?(expected_event, recorded.name) &&
|
|
104
121
|
self.payloads_match?(expected_payload, recorded.payload)
|
|
105
122
|
end
|
|
106
123
|
|
|
107
124
|
if match
|
|
108
|
-
self.add_matched(expected_event, expected_payload)
|
|
125
|
+
self.add_matched(expected_event, expected_payload, match)
|
|
109
126
|
else
|
|
110
127
|
self.add_missing(expected_event, expected_payload)
|
|
111
128
|
end
|
|
@@ -113,6 +130,7 @@ module Amigo
|
|
|
113
130
|
end
|
|
114
131
|
|
|
115
132
|
def event_names_match?(expected, actual)
|
|
133
|
+
return true if expected.nil?
|
|
116
134
|
return expected.matches?(actual) if expected.respond_to?(:matches?)
|
|
117
135
|
return expected.match?(actual) if expected.respond_to?(:match?)
|
|
118
136
|
return expected == actual
|
|
@@ -123,8 +141,8 @@ module Amigo
|
|
|
123
141
|
return expected.nil? || expected.empty? || expected == actual
|
|
124
142
|
end
|
|
125
143
|
|
|
126
|
-
def add_matched(
|
|
127
|
-
@matched << [
|
|
144
|
+
def add_matched(topic, payload, event)
|
|
145
|
+
@matched << [topic, payload, event]
|
|
128
146
|
end
|
|
129
147
|
|
|
130
148
|
def add_missing(event, payload)
|
|
@@ -156,10 +174,12 @@ module Amigo
|
|
|
156
174
|
|
|
157
175
|
def failure_message_when_negated
|
|
158
176
|
messages = []
|
|
159
|
-
@matched.each do |
|
|
160
|
-
message = "expected a '
|
|
161
|
-
message <<
|
|
162
|
-
message << " but one was
|
|
177
|
+
@matched.each do |topic, payload, event|
|
|
178
|
+
message = "expected a '#{topic || event.name}' event not to be fired"
|
|
179
|
+
message << " with a payload of #{payload.inspect}" if payload
|
|
180
|
+
message << " but one was"
|
|
181
|
+
event.payload.any? && message << ": #{event.payload.inspect}"
|
|
182
|
+
message << "."
|
|
163
183
|
messages << message
|
|
164
184
|
end
|
|
165
185
|
|
data/lib/amigo/version.rb
CHANGED