wisper-sidekiq 0.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +4 -0
- data/.travis.yml +12 -6
- data/CHANGELOG.md +17 -0
- data/Gemfile +3 -1
- data/README.md +27 -0
- data/lib/wisper/sidekiq.rb +24 -3
- data/lib/wisper/sidekiq/version.rb +1 -1
- data/scripts/sidekiq +1 -1
- data/spec/dummy_app/app.rb +1 -0
- data/spec/dummy_app/logs/.gitkeep +0 -0
- data/spec/dummy_app/subscriber.rb +1 -0
- data/spec/integration_spec.rb +20 -9
- data/spec/spec_helper.rb +12 -2
- data/spec/wisper/sidekiq_broadcaster_spec.rb +60 -0
- data/wisper-sidekiq.gemspec +1 -1
- metadata +12 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d4a87b1984ea51dd3c4dbe8dbc50938a440512819d96c0c4b374cf1a83bfe2b9
|
4
|
+
data.tar.gz: 63f801ae2bb5cf886d0e42ccad8b48e1932087fbd04d3c15e0ca0642b8860855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5127870825c7c90e0f73c68d109a4aa5948915d71294d3a53e2ceb9f7b31e6aba0b26b416a079404614f506e5220591690fafd29592fe656b2aced565f52d7d9
|
7
|
+
data.tar.gz: 1b9096f56361e21c2afc69dee9a30a1bab88ca43a49aefe410bbcd2a70c57538131e822126e3944e15fe2299264aee5bb330ca5d4b37d85643ea56534598d988
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
script: bundle exec rspec
|
3
5
|
bundler_args: --without=extras
|
4
|
-
|
5
|
-
-
|
6
|
-
-
|
7
|
-
- jruby
|
8
|
-
- rbx-2
|
6
|
+
before_script:
|
7
|
+
- bundle exec sidekiq -r ./spec/dummy_app/app.rb -L /tmp/sidekiq.log &
|
8
|
+
- sleep 1
|
9
9
|
services:
|
10
10
|
- redis-server
|
11
|
+
rvm:
|
12
|
+
- 2.2.10
|
13
|
+
- 2.3.7
|
14
|
+
- 2.4.4
|
15
|
+
- 2.5.1
|
16
|
+
- jruby-9.1.17.0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [1.1.0] - 28/Sept/2018
|
4
|
+
|
5
|
+
- fixes: `NoMethodError: undefined method `set' for
|
6
|
+
Wisper::SidekiqBroadcaster::Worker:Class` when using Sidekiq 2.x and 3.x.
|
7
|
+
|
8
|
+
## [1.0.0] - 28/Sept/2018
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- sidekiq 5 compatibility (closes [#11](https://github.com/krisleech/wisper-sidekiq/issues/11))
|
12
|
+
- support for optional `sidekiq_options` per subscriber class (closes [#15](https://github.com/krisleech/wisper-sidekiq/issues/15))
|
13
|
+
|
14
|
+
## [0.0.1] - 06-10-2014
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Initial release
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -23,6 +23,15 @@ publisher.subscribe(MyListener, async: true)
|
|
23
23
|
The listener must be a class (or module), not an object. This is because Sidekiq
|
24
24
|
can not reconstruct the state of an object. However a class is easily reconstructed.
|
25
25
|
|
26
|
+
Additionally, you should also ensure that your methods used to handle events under `MyListener` are all declared as class methods:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class MyListener
|
30
|
+
def self.event_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
26
35
|
When publshing events the arguments must be simple as they need to be
|
27
36
|
serialized. For example instead of sending an `ActiveRecord` model as an argument
|
28
37
|
use its id instead.
|
@@ -30,6 +39,24 @@ use its id instead.
|
|
30
39
|
See the [Sidekiq best practices](https://github.com/mperham/sidekiq/wiki/Best-Practices)
|
31
40
|
for more information.
|
32
41
|
|
42
|
+
### Passing down sidekiq options
|
43
|
+
|
44
|
+
In order to define custom [sidekiq_options](https://github.com/mperham/sidekiq/wiki/Advanced-Options#workers) you can add `sidekiq_options` class method in your subscriber definition - those options will be passed to Sidekiq's `set` method just before scheduling the asynchronous worker.
|
45
|
+
|
46
|
+
## Compatibility
|
47
|
+
|
48
|
+
The same Ruby versions as Sidekiq are offically supported, but it should work
|
49
|
+
with any 2.x syntax Ruby including JRuby and Rubinius.
|
50
|
+
|
51
|
+
See the [build status](https://travis-ci.org/krisleech/wisper-sidekiq) for details.
|
52
|
+
|
53
|
+
## Running Specs
|
54
|
+
|
55
|
+
```
|
56
|
+
scripts/sidekiq
|
57
|
+
bundle exec rspec
|
58
|
+
```
|
59
|
+
|
33
60
|
## Contributing
|
34
61
|
|
35
62
|
To run sidekiq use `scripts/sidekiq`. This wraps sidekiq in [rerun](https://github.com/alexch/rerun)
|
data/lib/wisper/sidekiq.rb
CHANGED
@@ -1,12 +1,22 @@
|
|
1
|
+
require 'yaml'
|
1
2
|
require 'wisper'
|
2
3
|
require 'sidekiq'
|
3
|
-
|
4
4
|
require 'wisper/sidekiq/version'
|
5
5
|
|
6
6
|
module Wisper
|
7
|
+
|
8
|
+
# based on Sidekiq 4.x #delay method, which is not enabled by default in Sidekiq 5.x
|
9
|
+
# https://github.com/mperham/sidekiq/blob/4.x/lib/sidekiq/extensions/generic_proxy.rb
|
10
|
+
# https://github.com/mperham/sidekiq/blob/4.x/lib/sidekiq/extensions/class_methods.rb
|
11
|
+
|
7
12
|
class SidekiqBroadcaster
|
8
|
-
|
9
|
-
|
13
|
+
class Worker
|
14
|
+
include ::Sidekiq::Worker
|
15
|
+
|
16
|
+
def perform(yml)
|
17
|
+
(subscriber, event, args) = ::YAML.load(yml)
|
18
|
+
subscriber.public_send(event, *args)
|
19
|
+
end
|
10
20
|
end
|
11
21
|
|
12
22
|
def self.register
|
@@ -15,6 +25,17 @@ module Wisper
|
|
15
25
|
config.broadcaster :async, SidekiqBroadcaster.new
|
16
26
|
end
|
17
27
|
end
|
28
|
+
|
29
|
+
def broadcast(subscriber, publisher, event, args)
|
30
|
+
options = sidekiq_options(subscriber)
|
31
|
+
Worker.set(options).perform_async(::YAML.dump([subscriber, event, args]))
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def sidekiq_options(subscriber)
|
37
|
+
subscriber.respond_to?(:sidekiq_options) ? subscriber.sidekiq_options : {}
|
38
|
+
end
|
18
39
|
end
|
19
40
|
end
|
20
41
|
|
data/scripts/sidekiq
CHANGED
data/spec/dummy_app/app.rb
CHANGED
File without changes
|
data/spec/integration_spec.rb
CHANGED
@@ -9,12 +9,22 @@ RSpec.describe 'integration tests:' do
|
|
9
9
|
include Wisper::Publisher
|
10
10
|
|
11
11
|
def run
|
12
|
-
broadcast(:it_happened,
|
12
|
+
broadcast(:it_happened, { hello: 'world' })
|
13
13
|
end
|
14
14
|
end.new
|
15
15
|
end
|
16
|
+
let(:shared_content) { File.read('/tmp/shared') }
|
17
|
+
|
18
|
+
def ensure_sidekiq_was_running
|
19
|
+
Timeout.timeout(10) do
|
20
|
+
while !File.exist?('/tmp/shared')
|
21
|
+
sleep(0.1)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
16
25
|
|
17
26
|
before do
|
27
|
+
Sidekiq::Testing.disable!
|
18
28
|
Sidekiq::Queue.new.clear
|
19
29
|
Sidekiq::RetrySet.new.clear
|
20
30
|
File.delete('/tmp/shared') if File.exist?('/tmp/shared')
|
@@ -22,16 +32,17 @@ RSpec.describe 'integration tests:' do
|
|
22
32
|
|
23
33
|
it 'performs event in a different process' do
|
24
34
|
publisher.subscribe(Subscriber, async: Wisper::SidekiqBroadcaster.new)
|
25
|
-
|
26
35
|
publisher.run
|
36
|
+
ensure_sidekiq_was_running
|
27
37
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
expect(shared_content).not_to include("pid: #{Process.pid}\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'performs event' do
|
42
|
+
publisher.subscribe(Subscriber, async: Wisper::SidekiqBroadcaster.new)
|
43
|
+
publisher.run
|
44
|
+
ensure_sidekiq_was_running
|
33
45
|
|
34
|
-
shared_content
|
35
|
-
expect(shared_content).not_to eq "pid: #{Process.pid}\n"
|
46
|
+
expect(shared_content).to include('{:hello=>"world"}')
|
36
47
|
end
|
37
48
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
require 'coveralls'
|
2
|
-
|
2
|
+
require 'simplecov'
|
3
|
+
require 'pry' unless ENV['CI']
|
4
|
+
require 'sidekiq/testing'
|
5
|
+
|
6
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
7
|
+
|
8
|
+
SimpleCov.start { add_filter 'spec/dummy_app' }
|
9
|
+
|
10
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
11
|
+
YAML::ENGINE.yamler = 'psych'
|
12
|
+
end
|
3
13
|
|
4
14
|
RSpec.configure do |config|
|
5
15
|
config.expect_with :rspec do |expectations|
|
@@ -21,7 +31,7 @@ RSpec.configure do |config|
|
|
21
31
|
config.default_formatter = 'doc'
|
22
32
|
end
|
23
33
|
|
24
|
-
config.profile_examples =
|
34
|
+
config.profile_examples = 0
|
25
35
|
|
26
36
|
config.order = :random
|
27
37
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'wisper/sidekiq'
|
2
|
+
|
3
|
+
RSpec.describe Wisper::SidekiqBroadcaster do
|
4
|
+
class PublisherUnderTest
|
5
|
+
include Wisper::Publisher
|
6
|
+
|
7
|
+
def run
|
8
|
+
broadcast(:it_happened)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class RegularSubscriberUnderTest
|
13
|
+
def self.it_happened(*_)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class CustomizedSubscriberUnderTest
|
18
|
+
def self.it_happened
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.sidekiq_options
|
22
|
+
{ queue: "my_queue" }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:publisher) { PublisherUnderTest.new }
|
27
|
+
|
28
|
+
before { Sidekiq::Testing.fake! }
|
29
|
+
after { Sidekiq::Testing.disable! }
|
30
|
+
|
31
|
+
describe '#broadcast' do
|
32
|
+
it 'schedules a sidekiq job' do
|
33
|
+
publisher.subscribe(RegularSubscriberUnderTest, async: described_class.new)
|
34
|
+
|
35
|
+
expect { publisher.run }
|
36
|
+
.to change(Sidekiq::Queues["default"], :size).by(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'can respect custom sidekiq_options' do
|
40
|
+
publisher.subscribe(CustomizedSubscriberUnderTest, async: described_class.new)
|
41
|
+
|
42
|
+
expect { publisher.run }
|
43
|
+
.to change(Sidekiq::Queues["my_queue"], :size).by(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when provides subscriber with args' do
|
47
|
+
let(:subscriber) { RegularSubscriberUnderTest }
|
48
|
+
let(:event) { 'it_happened' }
|
49
|
+
let(:args) { [1,2,3] }
|
50
|
+
|
51
|
+
subject(:broadcast_event) { described_class.new.broadcast(subscriber, nil, event, args) }
|
52
|
+
|
53
|
+
it 'subscriber receives event with corrects args' do
|
54
|
+
expect(RegularSubscriberUnderTest).to receive(event).with(*args)
|
55
|
+
|
56
|
+
Sidekiq::Testing.inline! { broadcast_event }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/wisper-sidekiq.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wisper-sidekiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Leech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wisper
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: sidekiq
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '4.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '4.0'
|
41
41
|
description: Async publishing for Wisper using Sidekiq
|
42
42
|
email:
|
43
43
|
- kris.leech@gmail.com
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rspec"
|
50
50
|
- ".travis.yml"
|
51
|
+
- CHANGELOG.md
|
51
52
|
- Gemfile
|
52
53
|
- LICENSE.txt
|
53
54
|
- README.md
|
@@ -57,9 +58,11 @@ files:
|
|
57
58
|
- scripts/sidekiq
|
58
59
|
- spec/configuration_spec.rb
|
59
60
|
- spec/dummy_app/app.rb
|
61
|
+
- spec/dummy_app/logs/.gitkeep
|
60
62
|
- spec/dummy_app/subscriber.rb
|
61
63
|
- spec/integration_spec.rb
|
62
64
|
- spec/spec_helper.rb
|
65
|
+
- spec/wisper/sidekiq_broadcaster_spec.rb
|
63
66
|
- wisper-sidekiq.gemspec
|
64
67
|
homepage: https://github.com/krisleech/wisper-sidekiq
|
65
68
|
licenses:
|
@@ -81,13 +84,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
84
|
version: '0'
|
82
85
|
requirements: []
|
83
86
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.7.6
|
85
88
|
signing_key:
|
86
89
|
specification_version: 4
|
87
90
|
summary: Async publishing for Wisper using Sidekiq
|
88
91
|
test_files:
|
89
92
|
- spec/configuration_spec.rb
|
90
93
|
- spec/dummy_app/app.rb
|
94
|
+
- spec/dummy_app/logs/.gitkeep
|
91
95
|
- spec/dummy_app/subscriber.rb
|
92
96
|
- spec/integration_spec.rb
|
93
97
|
- spec/spec_helper.rb
|
98
|
+
- spec/wisper/sidekiq_broadcaster_spec.rb
|