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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f0b35c819932228defa3d245462af3130c68e0b1
4
- data.tar.gz: d2e23253a221af849da6457a0c94f6611c48556c
2
+ SHA256:
3
+ metadata.gz: d4a87b1984ea51dd3c4dbe8dbc50938a440512819d96c0c4b374cf1a83bfe2b9
4
+ data.tar.gz: 63f801ae2bb5cf886d0e42ccad8b48e1932087fbd04d3c15e0ca0642b8860855
5
5
  SHA512:
6
- metadata.gz: 9bff0b75ae7ee15e2596c3efc27ac386b7ac5ac62590cf70c24d465d0717ab7cbdcbcfb344763114fc534ed904228ba3fcc73538d592ee40a3c0c377cc0f6626
7
- data.tar.gz: 32c654e236dc7ee0c00808ab258c0885f22e9eb99a45db7ae72b230160f96325b5674f3604ed0a722cc6952d9bb8d0a0abcd7760629d946f07305093d9fdcd1e
6
+ metadata.gz: 5127870825c7c90e0f73c68d109a4aa5948915d71294d3a53e2ceb9f7b31e6aba0b26b416a079404614f506e5220591690fafd29592fe656b2aced565f52d7d9
7
+ data.tar.gz: 1b9096f56361e21c2afc69dee9a30a1bab88ca43a49aefe410bbcd2a70c57538131e822126e3944e15fe2299264aee5bb330ca5d4b37d85643ea56534598d988
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.log
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -20,3 +21,6 @@ tmp
20
21
  *.o
21
22
  *.a
22
23
  mkmf.log
24
+ .ruby-version
25
+ .ruby-gemset
26
+ .idea
data/.travis.yml CHANGED
@@ -1,10 +1,16 @@
1
1
  language: ruby
2
- script: rspec spec
2
+ sudo: false
3
+ cache: bundler
4
+ script: bundle exec rspec
3
5
  bundler_args: --without=extras
4
- rvm:
5
- - '2.0.0'
6
- - '2.1.2'
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
@@ -7,7 +7,9 @@ gem 'rake'
7
7
  gem 'rspec'
8
8
  gem 'coveralls', require: false
9
9
 
10
+ gem 'psych', platforms: :rbx
11
+
10
12
  group :extras do
11
13
  gem 'rerun'
12
- gem 'pry'
14
+ gem 'pry-byebug'
13
15
  end
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)
@@ -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
- def broadcast(subscriber, publisher, event, args)
9
- subscriber.delay.public_send(event, *args)
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
 
@@ -1,5 +1,5 @@
1
1
  module Wisper
2
2
  module Sidekiq
3
- VERSION = "0.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
data/scripts/sidekiq CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  set -e
4
4
 
5
- bundle exec rerun --dir spec/dummy_app/ -- bundle exec sidekiq -r ./spec/dummy_app/app.rb
5
+ bundle exec rerun --dir spec/dummy_app/ -- bundle exec sidekiq -r ./spec/dummy_app/app.rb -L ./spec/dummy_app/logs/sidekiq.log
@@ -1,3 +1,4 @@
1
1
  # This is loaded by Sidekiq
2
2
 
3
+ require 'wisper/sidekiq'
3
4
  require_relative 'subscriber'
File without changes
@@ -2,6 +2,7 @@ class Subscriber
2
2
  def self.it_happened(message)
3
3
  File.open('/tmp/shared', 'w') do |file|
4
4
  file.puts "pid: #{Process.pid}"
5
+ file.puts message.inspect
5
6
  end
6
7
  end
7
8
  end
@@ -9,12 +9,22 @@ RSpec.describe 'integration tests:' do
9
9
  include Wisper::Publisher
10
10
 
11
11
  def run
12
- broadcast(:it_happened, 'hello, world')
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
- Timeout.timeout(10) do
29
- while !File.exist?('/tmp/shared')
30
- sleep(0.1)
31
- end
32
- end
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 = File.read('/tmp/shared')
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
- Coveralls.wear!
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 = 10
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
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'wisper'
22
- spec.add_dependency 'sidekiq'
22
+ spec.add_dependency 'sidekiq', '~>4.0'
23
23
  end
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: 0.0.1
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: 2014-10-06 00:00:00.000000000 Z
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.2.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