sidekiq-eventbus 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 6cee5a4ecfbeb86566ece98a9d419e008f3b1e82
4
- data.tar.gz: eb2bbd145e485b05c195b81fa217f3ffd18a452c
3
+ metadata.gz: b07d3cbd633ccb68fff5975cecbae3dae4b7b629
4
+ data.tar.gz: 337a6cc7e3e74b4a9017688ad8b5bbc57fb96e72
5
5
  SHA512:
6
- metadata.gz: 149ea8e9306733ca7777b4e7ace73bd670228e977e567061aeeb1f9d975834c6bc05132c38c0a3ead4e31b2be7acbc5dc2707a32846aa8dfb4d08b431028ca3e
7
- data.tar.gz: 5136f83e2f4ec1c8f3ff416cf414f96bb60b7e15c6a64b480202e3e094eaa4f68d64f596d025ed94c9b15af8061b88681fb58346b0bc72a63cccd2868d3d84cb
6
+ metadata.gz: 798b92159ba82596f5de181eaf4f7f6ab9d6c7990c0024e422646ceb5deca47df9f17ce948d76f8c6e1c8ec32bb23ea2f4150b6e6a1142f281f97bebc4c229b5
7
+ data.tar.gz: d60a26981ebdc5e5dd32be0d23bfbb4e211c116e254466b51ba88e052137a627822457003060099a2be7443b460ce3bf8875bb5e9e6f6386acbcaefe6116c968
@@ -0,0 +1,53 @@
1
+ require 'concurrent'
2
+
3
+ class Sidekiq::EventBus::Adapters::Buffered
4
+ def initialize adapter: Sidekiq::EventBus::Adapters::Default.new
5
+ @adapter = adapter
6
+ @bufferes = Concurrent::Map.new
7
+ end
8
+
9
+ def push topic, event, payload
10
+ if is_buffered?
11
+ event_buffer << [ topic, event, payload ]
12
+ nil
13
+ else
14
+ @adapter.push(topic, event, payload)
15
+ end
16
+ end
17
+
18
+ def buffered
19
+ buffer!
20
+ begin
21
+ yield
22
+ flush!
23
+ ensure
24
+ clear!
25
+ end
26
+ end
27
+
28
+ def event_buffer
29
+ @bufferes[buffer_key] ||= Array.new
30
+ end
31
+
32
+ def is_buffered?
33
+ @bufferes.key?(buffer_key)
34
+ end
35
+
36
+ def buffer!
37
+ @bufferes[buffer_key] ||= Array.new
38
+ end
39
+
40
+ def flush!
41
+ event_buffer.map do |topic, event, payload|
42
+ @adapter.push(topic, event, payload)
43
+ end
44
+ end
45
+
46
+ def clear!
47
+ @bufferes.delete(buffer_key)
48
+ end
49
+
50
+ def buffer_key
51
+ Thread.current.object_id
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ module Sidekiq
2
+ module EventBus
3
+ VERSION = '0.0.5'
4
+ end
5
+ end
@@ -13,9 +13,10 @@ module Sidekiq
13
13
 
14
14
  module Adapters
15
15
  autoload :Default, 'sidekiq/event_bus/adapters/default'
16
+ autoload :Buffered, 'sidekiq/event_bus/adapters/buffered'
16
17
  autoload :Inline, 'sidekiq/event_bus/adapters/inline'
17
18
  autoload :Test, 'sidekiq/event_bus/adapters/test'
18
- autoload :Log, 'sidekiq/event_bus/adapters/log'
19
+ autoload :Log, 'sidekiq/event_bus/adapters/log'
19
20
  end
20
21
 
21
22
  def self.config
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-eventbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Monroe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-21 00:00:00.000000000 Z
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -61,6 +61,7 @@ files:
61
61
  - README.md
62
62
  - lib/sidekiq-eventbus.rb
63
63
  - lib/sidekiq/event_bus.rb
64
+ - lib/sidekiq/event_bus/adapters/buffered.rb
64
65
  - lib/sidekiq/event_bus/adapters/default.rb
65
66
  - lib/sidekiq/event_bus/adapters/inline.rb
66
67
  - lib/sidekiq/event_bus/adapters/log.rb
@@ -71,6 +72,7 @@ files:
71
72
  - lib/sidekiq/event_bus/producer.rb
72
73
  - lib/sidekiq/event_bus/topic_middleware.rb
73
74
  - lib/sidekiq/event_bus/utils.rb
75
+ - lib/sidekiq/event_bus/version.rb
74
76
  homepage: https://github.com/Rakefire/sidekiq-eventbus
75
77
  licenses:
76
78
  - MIT