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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dc6d4ac6f9e7a89afecc711780ceeeb3ab1204435a19be2683623256b2abc49
4
- data.tar.gz: 725dc4719b949d5f93bd84125ed6d2bea713be872f7e8413e6509d90c9090544
3
+ metadata.gz: 53361c37c9ec31b3886fb7b33ff61bd022802128b458f93e624c4f0d0cbcc963
4
+ data.tar.gz: 54a9e75e5b011d6441b8906404a0d856394e19c4d27e66e7580c37d4928e3d41
5
5
  SHA512:
6
- metadata.gz: e1a5e2c7beab44fecabb7d7b7f9f610ce1138029eb247b46c04d90399550d976990f6db36717c73f225c195318ea303b1607984878167dfac4087024e809c735
7
- data.tar.gz: 807e4c88665fd4ac7a6a4004e654de2a697b4ebd7c90546be7f965955ecd84690f2e0f5eebe913d31e2673f32f7bbd560e05695f79154284f3d7bd8a6ee77eb9
6
+ metadata.gz: b469583cc5c2e339d359834763d3a67c154e9977212b35f039623f937b4b55997b7a523ba8f5c414898295c18c65d401a020b9679c4d695c50d636ef5c7334db
7
+ data.tar.gz: ab70f5da69a2bb8868c9ec864c760eb1d6fc124a99d71e2ad332a8dccd7ba8503971dfb0ee3a60d19d122e5ce079b5f9a4dc6a5a3df2a8c05057b19f2963c172
@@ -16,18 +16,28 @@ module Amigo
16
16
  end
17
17
 
18
18
  module_function def snapshot_async_state(opts={})
19
- old_hooks = Amigo.subscribers.to_a
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(opts[:subscribers]) if opts.key?(:subscribers)
26
- Amigo.registered_jobs.replace(opts[:jobs]) if opts.key?(:jobs)
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(old_hooks)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Amigo
4
- VERSION = "1.2.1"
4
+ VERSION = "1.2.2"
5
5
  end
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 self.deep_stringify_keys(o) if o.is_a?(Hash)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-amigo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lithic Technology