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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7061dd705796ed74b0ee5cf0728d269b06ac341e
4
- data.tar.gz: 1f44778cbd38de46eb79f8e2f291da182d2f4f20
2
+ SHA256:
3
+ metadata.gz: e246cbcc36a0dd6d362dc9c5d505094ecd66bf11e620334cd80ca3e1b9042b97
4
+ data.tar.gz: ba94de9927238c7d79c018d3c4776f1c7ca35eb0f989a5994c6a2c71d5f3a888
5
5
  SHA512:
6
- metadata.gz: b98e138821232d05837624b86c653de82af593d7678139a9071f91963760ea647f0447c11fbe3f8da08101406707edd0bbaa4b752c6471dfc1fd6cb35de900b4
7
- data.tar.gz: aea550b45556040b2dee7d0dbd0c6a7baeb8626f45c6dcf962d370aca66549aad390295da83e0cc22323a7a8ac5ff2932ad8126fd87875e0b4d193b5719bd5b6
6
+ metadata.gz: c2265fdd50b3c914024bada3ee1012044d6eb2f7aca03c3961940e07e814a01b18717124aa8fabe0d19b48a4d1b6a0e40e4d537778cf062299feb7a85219a7f2
7
+ data.tar.gz: f7ab5f88503302c094bd0616c60db5fd5d9d2b7b63dc7c216239e18ea1c7f920d85b1343a12f25275c93dcd13ee9e26c083429b73f4b3c12b1b3de73cd31e790
@@ -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 topic, event, payload
9
+ def push event, payload
10
10
  if is_buffered?
11
- event_buffer << [ topic, event, payload ]
11
+ event_buffer << [ event, payload ]
12
12
  nil
13
13
  else
14
- @adapter.push(topic, event, payload)
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 |topic, event, payload|
42
- @adapter.push(topic, event, payload)
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 topic, event, payload
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,6 +1,6 @@
1
1
  class Sidekiq::EventBus::Adapters::Inline
2
- def push topic, event, payload
3
- Sidekiq::EventBus.utils.handle_event(topic, event, payload)
2
+ def push event, payload
3
+ Sidekiq::EventBus.utils.handle_event(event, payload)
4
4
  SecureRandom.hex(8)
5
5
  end
6
- end
6
+ end
@@ -1,7 +1,7 @@
1
1
  class Sidekiq::EventBus::Adapters::Log
2
- def push topic, event, payload
2
+ def push event, payload
3
3
  id = SecureRandom.hex(8)
4
- puts "topic=#{topic} event=#{event} id=#{id} payload=#{payload.to_json}"
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 :topics
2
+ attr_accessor :events
3
3
 
4
4
  def initialize
5
- self.topics = Hash.new{ |hash, key| hash[key] = [] }
5
+ self.events = []
6
6
  end
7
7
 
8
- def push topic, event, payload
8
+ def push event, payload
9
9
  id = SecureRandom.hex(8)
10
- self.topics[topic].push({
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.topics.clear
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 = Hash.new { |hash, key| hash[key] = Set.new }
6
+ self.consumers = Set.new
7
7
  self.sidekiq_worker_options = { retry: 0, dead: true }
8
8
  end
9
9
 
10
- def register_consumer topic, klass
10
+ def register_consumer klass
11
11
  klass = klass.name unless klass.is_a?(String)
12
- consumers[topic] << klass
12
+ consumers << klass
13
13
  end
14
- end
14
+ end
@@ -1,12 +1,8 @@
1
1
  class Sidekiq::EventBus::Consumer
2
- # Register Consumer with the EventBus for a particular topic
3
- def self.topic *topics
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 topic, event, payload
23
+ def consume event, payload
28
24
  if self.class.handlers.key? event
29
- _payload = payload.merge('topic'.freeze => topic, 'event'.freeze => event).freeze
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(topic, event, payload)
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 :topics, :adapter
2
+ attr_reader :adapter
3
3
 
4
- def initialize topics:, adapter: Sidekiq::EventBus.config.adapter
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
- topics.map do |topic|
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 consumers_for topic
9
- config.consumers[topic].map do |klass_name|
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 topic, event, payload
15
- consumers_for(topic).each do |consumer|
16
- consumer.consume(topic, event, payload)
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
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module EventBus
3
- VERSION = '0.0.6'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  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.6
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: 2017-06-04 00:00:00.000000000 Z
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: '5.0'
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: '5.0'
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
- rubyforge_project:
96
- rubygems_version: 2.5.1
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: []
@@ -1,9 +0,0 @@
1
- class Sidekiq::EventBus::TopicMiddleware
2
- def initialize(options=nil)
3
- end
4
-
5
- def call(worker, msg, queue)
6
- worker.topic = queue if worker.respond_to?("topic=")
7
- yield
8
- end
9
- end