sidekiq-amigo 1.2.2 → 1.3.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/version.rb +1 -1
- data/lib/amigo.rb +29 -5
- 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: 56470f3e16978212a6e8a23d970c7709c0f24854b80c15d522989389e0cc829e
|
4
|
+
data.tar.gz: 2bed22f2a190e056aa715814f460ba009fd2c2d3884e6d34eb866084659af962
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18ac44e7cffa487844980f937193ac4601585e380aa08c85599591181271e3ded429271be3407d120e0bf280c541c0f9c28ca23c2c5e9a528deda26c16ca8735
|
7
|
+
data.tar.gz: 243229bf9a1f661eb6ef4b9fe847a979634fa729df34e756016f6f2c403ae1e8f73d444e437e640b86d300e38169a391b72f1676a49e985aeac11d41684c4974
|
data/lib/amigo/version.rb
CHANGED
data/lib/amigo.rb
CHANGED
@@ -140,7 +140,18 @@ module Amigo
|
|
140
140
|
# An Array of callbacks to be run when an event is published.
|
141
141
|
attr_accessor :subscribers
|
142
142
|
|
143
|
-
# A single callback to be run when an event publication errors
|
143
|
+
# A single callback to be run when an event publication errors,
|
144
|
+
# almost always due to an error in a subscriber.
|
145
|
+
#
|
146
|
+
# The callback receives the exception, the event being published, and the erroring subscriber.
|
147
|
+
#
|
148
|
+
# If this is not set, errors from subscribers will be re-raised immediately,
|
149
|
+
# since broken subscribers usually indicate a broken application.
|
150
|
+
#
|
151
|
+
# Note also that when an error occurs, Amigo.log is always called first.
|
152
|
+
# You do NOT need a callback that just logs and swallows the error.
|
153
|
+
# If all you want to do is log, and not propogate the error,
|
154
|
+
# you can use `Amigo.on_publish_error = proc {}`.
|
144
155
|
attr_accessor :on_publish_error
|
145
156
|
|
146
157
|
# Publish an event with the specified +eventname+ and +payload+
|
@@ -151,12 +162,18 @@ module Amigo
|
|
151
162
|
self.subscribers.to_a.each do |hook|
|
152
163
|
hook.call(ev)
|
153
164
|
rescue StandardError => e
|
154
|
-
self.log(nil, :error, "amigo_subscriber_hook_error", error: e, hook: hook, event: ev)
|
155
|
-
self.on_publish_error.
|
165
|
+
self.log(nil, :error, "amigo_subscriber_hook_error", error: e, hook: hook, event: ev&.as_json)
|
166
|
+
raise e if self.on_publish_error.nil?
|
167
|
+
if self.on_publish_error.respond_to?(:arity) && self.on_publish_error.arity == 1
|
168
|
+
self.on_publish_error.call(e)
|
169
|
+
else
|
170
|
+
self.on_publish_error.call(e, ev, hook)
|
171
|
+
end
|
156
172
|
end
|
157
173
|
end
|
158
174
|
|
159
175
|
# Register a hook to be called when an event is sent.
|
176
|
+
# If a subscriber errors, on_publish_error is called with the exception, event, and subscriber.
|
160
177
|
def register_subscriber(&block)
|
161
178
|
raise LocalJumpError, "no block given" unless block
|
162
179
|
self.log nil, :info, "amigo_installed_subscriber", block: block
|
@@ -191,7 +208,15 @@ module Amigo
|
|
191
208
|
|
192
209
|
def _subscriber(event)
|
193
210
|
event_json = event.as_json
|
194
|
-
|
211
|
+
begin
|
212
|
+
self.audit_logger_class.perform_async(event_json)
|
213
|
+
rescue StandardError => e
|
214
|
+
# If the audit logger cannot perform, let's say because Redis is down,
|
215
|
+
# we can run the job manually. This is pretty important for anything used for auditing;
|
216
|
+
# it should be as resilient as possible.
|
217
|
+
self.log(nil, :error, "amigo_audit_log_subscriber_error", error: e, event: event_json)
|
218
|
+
self.audit_logger_class.new.perform(event_json)
|
219
|
+
end
|
195
220
|
self.router_class.perform_async(event_json)
|
196
221
|
end
|
197
222
|
|
@@ -272,7 +297,6 @@ Amigo.reset_logging
|
|
272
297
|
Amigo.synchronous_mode = false
|
273
298
|
Amigo.registered_jobs = []
|
274
299
|
Amigo.subscribers = Set.new
|
275
|
-
Amigo.on_publish_error = proc {}
|
276
300
|
|
277
301
|
require "amigo/audit_logger"
|
278
302
|
require "amigo/router"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-amigo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lithic Technology
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|