sidekiq-eventbus 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/sidekiq/event_bus.rb +0 -7
- data/lib/sidekiq/event_bus/adapters/buffered.rb +6 -6
- data/lib/sidekiq/event_bus/adapters/default.rb +3 -4
- data/lib/sidekiq/event_bus/adapters/inline.rb +3 -3
- data/lib/sidekiq/event_bus/adapters/log.rb +3 -3
- data/lib/sidekiq/event_bus/adapters/test.rb +6 -7
- data/lib/sidekiq/event_bus/configuration.rb +4 -4
- data/lib/sidekiq/event_bus/consumer.rb +4 -8
- data/lib/sidekiq/event_bus/event_worker.rb +2 -4
- data/lib/sidekiq/event_bus/producer.rb +4 -7
- data/lib/sidekiq/event_bus/utils.rb +6 -6
- data/lib/sidekiq/event_bus/version.rb +1 -1
- metadata +28 -10
- data/lib/sidekiq/event_bus/topic_middleware.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e246cbcc36a0dd6d362dc9c5d505094ecd66bf11e620334cd80ca3e1b9042b97
|
4
|
+
data.tar.gz: ba94de9927238c7d79c018d3c4776f1c7ca35eb0f989a5994c6a2c71d5f3a888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2265fdd50b3c914024bada3ee1012044d6eb2f7aca03c3961940e07e814a01b18717124aa8fabe0d19b48a4d1b6a0e40e4d537778cf062299feb7a85219a7f2
|
7
|
+
data.tar.gz: f7ab5f88503302c094bd0616c60db5fd5d9d2b7b63dc7c216239e18ea1c7f920d85b1343a12f25275c93dcd13ee9e26c083429b73f4b3c12b1b3de73cd31e790
|
data/lib/sidekiq/event_bus.rb
CHANGED
@@ -8,7 +8,6 @@ module Sidekiq
|
|
8
8
|
autoload :Consumer, 'sidekiq/event_bus/consumer'
|
9
9
|
autoload :Producer, 'sidekiq/event_bus/producer'
|
10
10
|
|
11
|
-
autoload :TopicMiddleware, 'sidekiq/event_bus/topic_middleware'
|
12
11
|
autoload :EventWorker, 'sidekiq/event_bus/event_worker'
|
13
12
|
|
14
13
|
module Adapters
|
@@ -32,9 +31,3 @@ module Sidekiq
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
36
|
-
Sidekiq.configure_server do |config|
|
37
|
-
config.server_middleware do |chain|
|
38
|
-
chain.add Sidekiq::EventBus::TopicMiddleware
|
39
|
-
end
|
40
|
-
end
|
@@ -6,12 +6,12 @@ class Sidekiq::EventBus::Adapters::Buffered
|
|
6
6
|
@bufferes = Concurrent::Map.new
|
7
7
|
end
|
8
8
|
|
9
|
-
def push
|
9
|
+
def push event, payload
|
10
10
|
if is_buffered?
|
11
|
-
event_buffer << [
|
11
|
+
event_buffer << [ event, payload ]
|
12
12
|
nil
|
13
13
|
else
|
14
|
-
@adapter.push(
|
14
|
+
@adapter.push(event, payload)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -38,8 +38,8 @@ class Sidekiq::EventBus::Adapters::Buffered
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def flush!
|
41
|
-
event_buffer.map do |
|
42
|
-
@adapter.push(
|
41
|
+
event_buffer.map do |event, payload|
|
42
|
+
@adapter.push(event, payload)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -50,4 +50,4 @@ class Sidekiq::EventBus::Adapters::Buffered
|
|
50
50
|
def buffer_key
|
51
51
|
Thread.current.object_id
|
52
52
|
end
|
53
|
-
end
|
53
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
class Sidekiq::EventBus::Adapters::Default
|
2
|
-
def push
|
2
|
+
def push event, payload
|
3
3
|
Sidekiq::Client.push({
|
4
4
|
'class' => Sidekiq::EventBus::EventWorker,
|
5
|
-
'args' => [ event, payload ]
|
6
|
-
'queue' => topic,
|
5
|
+
'args' => [ event, payload ]
|
7
6
|
})
|
8
7
|
end
|
9
|
-
end
|
8
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Sidekiq::EventBus::Adapters::Log
|
2
|
-
def push
|
2
|
+
def push event, payload
|
3
3
|
id = SecureRandom.hex(8)
|
4
|
-
puts "
|
4
|
+
puts "event=#{event} id=#{id} payload=#{payload.to_json}"
|
5
5
|
id
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
class Sidekiq::EventBus::Adapters::Test
|
2
|
-
attr_accessor :
|
2
|
+
attr_accessor :events
|
3
3
|
|
4
4
|
def initialize
|
5
|
-
self.
|
5
|
+
self.events = []
|
6
6
|
end
|
7
7
|
|
8
|
-
def push
|
8
|
+
def push event, payload
|
9
9
|
id = SecureRandom.hex(8)
|
10
|
-
self.
|
11
|
-
topic: topic,
|
10
|
+
self.events.push({
|
12
11
|
event: event,
|
13
12
|
payload: payload,
|
14
13
|
id: id
|
@@ -18,6 +17,6 @@ class Sidekiq::EventBus::Adapters::Test
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def clear!
|
21
|
-
self.
|
20
|
+
self.events.clear
|
22
21
|
end
|
23
|
-
end
|
22
|
+
end
|
@@ -3,12 +3,12 @@ class Sidekiq::EventBus::Configuration
|
|
3
3
|
|
4
4
|
def initialize
|
5
5
|
self.adapter = Sidekiq::EventBus::Adapters::Default.new
|
6
|
-
self.consumers =
|
6
|
+
self.consumers = Set.new
|
7
7
|
self.sidekiq_worker_options = { retry: 0, dead: true }
|
8
8
|
end
|
9
9
|
|
10
|
-
def register_consumer
|
10
|
+
def register_consumer klass
|
11
11
|
klass = klass.name unless klass.is_a?(String)
|
12
|
-
consumers
|
12
|
+
consumers << klass
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
@@ -1,12 +1,8 @@
|
|
1
1
|
class Sidekiq::EventBus::Consumer
|
2
|
-
|
3
|
-
|
4
|
-
Array(topics).each do |topic|
|
5
|
-
Sidekiq::EventBus.config.register_consumer(topic, self)
|
6
|
-
end
|
2
|
+
def self.register_consumer!
|
3
|
+
Sidekiq::EventBus.config.register_consumer(self)
|
7
4
|
end
|
8
5
|
|
9
|
-
|
10
6
|
# Store handlers for this consumer
|
11
7
|
def self.handlers
|
12
8
|
@handlers ||= Hash.new { |hash, key| hash[key] = Array.new }
|
@@ -24,9 +20,9 @@ class Sidekiq::EventBus::Consumer
|
|
24
20
|
|
25
21
|
PAYLOAD_WITH_INDIFFERENT_ACCESS = defined?(ActiveSupport::HashWithIndifferentAccess)
|
26
22
|
|
27
|
-
def consume
|
23
|
+
def consume event, payload
|
28
24
|
if self.class.handlers.key? event
|
29
|
-
_payload = payload.merge('
|
25
|
+
_payload = payload.merge('event'.freeze => event).freeze
|
30
26
|
|
31
27
|
if PAYLOAD_WITH_INDIFFERENT_ACCESS
|
32
28
|
_payload = ActiveSupport::HashWithIndifferentAccess.new(_payload)
|
@@ -1,11 +1,9 @@
|
|
1
1
|
class Sidekiq::EventBus::EventWorker
|
2
2
|
include Sidekiq::Worker
|
3
3
|
|
4
|
-
attr_accessor :topic
|
5
|
-
|
6
4
|
sidekiq_options Sidekiq::EventBus.config.sidekiq_worker_options
|
7
5
|
|
8
6
|
def perform(event, payload)
|
9
|
-
Sidekiq::EventBus.utils.handle_event(
|
7
|
+
Sidekiq::EventBus.utils.handle_event(event, payload)
|
10
8
|
end
|
11
|
-
end
|
9
|
+
end
|
@@ -1,14 +1,11 @@
|
|
1
1
|
class Sidekiq::EventBus::Producer
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :adapter
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
@topics = Array(topics)
|
4
|
+
def initialize adapter: Sidekiq::EventBus.config.adapter
|
6
5
|
@adapter = adapter
|
7
6
|
end
|
8
7
|
|
9
8
|
def publish event, payload
|
10
|
-
|
11
|
-
adapter.push topic, event, payload
|
12
|
-
end
|
9
|
+
adapter.push event, payload
|
13
10
|
end
|
14
|
-
end
|
11
|
+
end
|
@@ -5,15 +5,15 @@ class Sidekiq::EventBus::Utils
|
|
5
5
|
@config = config
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
config.consumers
|
8
|
+
def consumers
|
9
|
+
config.consumers.map do |klass_name|
|
10
10
|
klass_name.constantize.new
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def handle_event
|
15
|
-
|
16
|
-
consumer.consume(
|
14
|
+
def handle_event event, payload
|
15
|
+
consumers.each do |consumer|
|
16
|
+
consumer.consume(event, payload)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,4 +22,4 @@ class Sidekiq::EventBus::Utils
|
|
22
22
|
config.error_handler.call(exception)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-eventbus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Monroe
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: sidekiq
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -19,7 +39,7 @@ dependencies:
|
|
19
39
|
version: 4.0.0
|
20
40
|
- - "<"
|
21
41
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
42
|
+
version: '7.0'
|
23
43
|
type: :runtime
|
24
44
|
prerelease: false
|
25
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +49,7 @@ dependencies:
|
|
29
49
|
version: 4.0.0
|
30
50
|
- - "<"
|
31
51
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
52
|
+
version: '7.0'
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: rspec
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,14 +90,13 @@ files:
|
|
70
90
|
- lib/sidekiq/event_bus/consumer.rb
|
71
91
|
- lib/sidekiq/event_bus/event_worker.rb
|
72
92
|
- lib/sidekiq/event_bus/producer.rb
|
73
|
-
- lib/sidekiq/event_bus/topic_middleware.rb
|
74
93
|
- lib/sidekiq/event_bus/utils.rb
|
75
94
|
- lib/sidekiq/event_bus/version.rb
|
76
95
|
homepage: https://github.com/Rakefire/sidekiq-eventbus
|
77
96
|
licenses:
|
78
97
|
- MIT
|
79
98
|
metadata: {}
|
80
|
-
post_install_message:
|
99
|
+
post_install_message:
|
81
100
|
rdoc_options: []
|
82
101
|
require_paths:
|
83
102
|
- lib
|
@@ -92,9 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
111
|
- !ruby/object:Gem::Version
|
93
112
|
version: '0'
|
94
113
|
requirements: []
|
95
|
-
|
96
|
-
|
97
|
-
signing_key:
|
114
|
+
rubygems_version: 3.0.3
|
115
|
+
signing_key:
|
98
116
|
specification_version: 4
|
99
117
|
summary: Producer/Consumer event bus via Sidekiq
|
100
118
|
test_files: []
|