sidekiq-amigo 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/amigo/spec_helpers.rb +14 -4
- data/lib/amigo/version.rb +1 -1
- data/lib/amigo.rb +11 -17
- 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: 53361c37c9ec31b3886fb7b33ff61bd022802128b458f93e624c4f0d0cbcc963
|
4
|
+
data.tar.gz: 54a9e75e5b011d6441b8906404a0d856394e19c4d27e66e7580c37d4928e3d41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b469583cc5c2e339d359834763d3a67c154e9977212b35f039623f937b4b55997b7a523ba8f5c414898295c18c65d401a020b9679c4d695c50d636ef5c7334db
|
7
|
+
data.tar.gz: ab70f5da69a2bb8868c9ec864c760eb1d6fc124a99d71e2ad332a8dccd7ba8503971dfb0ee3a60d19d122e5ce079b5f9a4dc6a5a3df2a8c05057b19f2963c172
|
data/lib/amigo/spec_helpers.rb
CHANGED
@@ -16,18 +16,28 @@ module Amigo
|
|
16
16
|
end
|
17
17
|
|
18
18
|
module_function def snapshot_async_state(opts={})
|
19
|
-
|
19
|
+
old_subscribers = Amigo.subscribers.to_a
|
20
20
|
old_jobs = Amigo.registered_jobs.to_a
|
21
21
|
old_failure = Amigo.on_publish_error
|
22
22
|
|
23
|
+
new_subscribers = opts.fetch(:subscribers, [])
|
24
|
+
new_jobs = opts.fetch(:jobs, [])
|
25
|
+
|
26
|
+
@active_snapshots ||= 0
|
27
|
+
if @active_snapshots.positive?
|
28
|
+
new_subscribers = old_subscribers + new_subscribers
|
29
|
+
new_jobs = old_jobs = new_jobs
|
30
|
+
end
|
23
31
|
begin
|
24
32
|
Amigo.on_publish_error = opts[:on_error] if opts.key?(:on_error)
|
25
|
-
Amigo.subscribers.replace(
|
26
|
-
Amigo.registered_jobs.replace(
|
33
|
+
Amigo.subscribers.replace(new_subscribers) if opts.key?(:subscribers)
|
34
|
+
Amigo.registered_jobs.replace(new_jobs) if opts.key?(:jobs)
|
35
|
+
@active_snapshots += 1
|
27
36
|
yield
|
28
37
|
ensure
|
38
|
+
@active_snapshots -= 1
|
29
39
|
Amigo.on_publish_error = old_failure
|
30
|
-
Amigo.subscribers.replace(
|
40
|
+
Amigo.subscribers.replace(old_subscribers)
|
31
41
|
Amigo.registered_jobs.replace(old_jobs)
|
32
42
|
end
|
33
43
|
end
|
data/lib/amigo/version.rb
CHANGED
data/lib/amigo.rb
CHANGED
@@ -217,6 +217,14 @@ module Amigo
|
|
217
217
|
end
|
218
218
|
|
219
219
|
class Event
|
220
|
+
# @param topic [String]
|
221
|
+
# @param payload [Array]
|
222
|
+
# @return [Webhookdb::Event]
|
223
|
+
def self.create(topic, payload)
|
224
|
+
return self.new(SecureRandom.uuid, topic, payload)
|
225
|
+
end
|
226
|
+
|
227
|
+
# @return [Webhookdb::Event]
|
220
228
|
def self.from_json(o)
|
221
229
|
return self.new(o["id"], o["name"], o["payload"])
|
222
230
|
end
|
@@ -252,25 +260,11 @@ module Amigo
|
|
252
260
|
end
|
253
261
|
|
254
262
|
protected def safe_stringify(o)
|
255
|
-
return
|
263
|
+
return o.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if o.is_a?(Time)
|
264
|
+
return o.each_with_object({}) { |(k, v), m| m[k.to_s] = safe_stringify(v) } if o.is_a?(Hash)
|
265
|
+
return o.map { |x| safe_stringify(x) } if o.is_a?(Array)
|
256
266
|
return o
|
257
267
|
end
|
258
|
-
|
259
|
-
def deep_stringify_keys(hash)
|
260
|
-
stringified_hash = {}
|
261
|
-
hash.each do |k, v|
|
262
|
-
stringified_hash[k.to_s] =
|
263
|
-
case v
|
264
|
-
when Hash
|
265
|
-
self.deep_stringify_keys(v)
|
266
|
-
when Array
|
267
|
-
v.map { |i| i.is_a?(Hash) ? self.deep_stringify_keys(i) : i }
|
268
|
-
else
|
269
|
-
v
|
270
|
-
end
|
271
|
-
end
|
272
|
-
stringified_hash
|
273
|
-
end
|
274
268
|
end
|
275
269
|
end
|
276
270
|
|