wisper-sidekiq-compat 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/test.yml +31 -0
- data/.gitignore +26 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +39 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +95 -0
- data/Rakefile +1 -0
- data/docker-compose.yml +5 -0
- data/lib/wisper/sidekiq/version.rb +5 -0
- data/lib/wisper/sidekiq.rb +70 -0
- data/scripts/sidekiq +5 -0
- data/spec/configuration_spec.rb +13 -0
- data/spec/dummy_app/app.rb +4 -0
- data/spec/dummy_app/subscriber.rb +8 -0
- data/spec/integration_spec.rb +48 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/wisper/sidekiq_broadcaster_spec.rb +162 -0
- data/wisper-sidekiq-compat.gemspec +24 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6a4388e72736b4fdac245dd3cdd98b9fd65b4b88f696f9ead73b394d32125e4
|
4
|
+
data.tar.gz: 20889dbe889541df920687d4aae172dbb8bb576e04f51299e19522e249c52f39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c0b102c2eb662bbca2a7ca78c0fe6463b210183dd9769af23a42cc8ca29eb87eaff5633f89241f4e359236441aef54964c0e5177c2d40dffd3f336e50049e1a
|
7
|
+
data.tar.gz: 29cfb34f718162a6fb297ff6b835551160bd5ea3ad28f379f3ea2fd7c77c8bad4b55d5345bff31114f29a1764cd4729bfda82ec45d147f8d181b7320130e27de
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
name: Test
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby: [3.0, 3.1, 3.2]
|
13
|
+
services:
|
14
|
+
redis:
|
15
|
+
image: redis:7-alpine
|
16
|
+
ports:
|
17
|
+
- "6379:6379"
|
18
|
+
options: >-
|
19
|
+
--health-cmd "redis-cli ping"
|
20
|
+
--health-interval 10s
|
21
|
+
--health-timeout 5s
|
22
|
+
--health-retries 5
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v3
|
25
|
+
- uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
28
|
+
bundler-cache: true
|
29
|
+
- run: |
|
30
|
+
scripts/sidekiq &
|
31
|
+
bundle exec rspec spec
|
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
*.log
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
24
|
+
.ruby-gemset
|
25
|
+
.idea
|
26
|
+
.gs
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [2.0.0] - 28/Feb/2023
|
4
|
+
|
5
|
+
## Changed
|
6
|
+
- Name of gem -> wisper-sidekiq-compat
|
7
|
+
|
8
|
+
## Removed
|
9
|
+
- Support for Ruby < 3
|
10
|
+
- Support for Sidekiq < 6.5
|
11
|
+
- Rubinius support
|
12
|
+
|
13
|
+
## Fixed
|
14
|
+
- Compatibility with wisper-compat
|
15
|
+
- `Psych::DisallowedClass: Tried to load unspecified class:` on Ruby 3.1
|
16
|
+
|
17
|
+
## [1.3.0] - 25/Nov/2019
|
18
|
+
|
19
|
+
- Add the ability to pass `sidekiq_schedule_options` options in order to schedule jobs to be run in the future
|
20
|
+
|
21
|
+
## [1.2.0]
|
22
|
+
|
23
|
+
- fixes: gemspec does not allow sidekiq 5.x to be used
|
24
|
+
|
25
|
+
## [1.1.0] - 28/Sept/2018
|
26
|
+
|
27
|
+
- fixes: `NoMethodError: undefined method `set' for
|
28
|
+
Wisper::SidekiqBroadcaster::Worker:Class` when using Sidekiq 2.x and 3.x.
|
29
|
+
|
30
|
+
## [1.0.0] - 28/Sept/2018
|
31
|
+
|
32
|
+
### Added
|
33
|
+
- sidekiq 5 compatibility (closes [#11](https://github.com/krisleech/wisper-sidekiq/issues/11))
|
34
|
+
- support for optional `sidekiq_options` per subscriber class (closes [#15](https://github.com/krisleech/wisper-sidekiq/issues/15))
|
35
|
+
|
36
|
+
## [0.0.1] - 06-10-2014
|
37
|
+
|
38
|
+
### Added
|
39
|
+
- Initial release
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kris Leech
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Wisper::Sidekiq
|
2
|
+
|
3
|
+
Provides [Wisper-Compat](https://github.com/nedap/wisper-compat) with asynchronous event
|
4
|
+
publishing using [Sidekiq](https://github.com/mperham/sidekiq).
|
5
|
+
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/wisper-sidekiq-compat.png)](http://badge.fury.io/rb/wisper-sidekiq-compat)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'wisper-sidekiq-compat'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
publisher.subscribe(MyListener, async: true)
|
18
|
+
```
|
19
|
+
|
20
|
+
The listener must be a class (or module), not an object. This is because Sidekiq
|
21
|
+
can not reconstruct the state of an object. However a class is easily reconstructed.
|
22
|
+
|
23
|
+
Additionally, you should also ensure that your methods used to handle events under `MyListener` are all declared as class methods:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class MyListener
|
27
|
+
def self.event_name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
When publishing events the arguments must be simple as they need to be
|
33
|
+
serialized. For example instead of sending an `ActiveRecord` model as an argument
|
34
|
+
use its id instead.
|
35
|
+
|
36
|
+
See the [Sidekiq best practices](https://github.com/mperham/sidekiq/wiki/Best-Practices)
|
37
|
+
for more information.
|
38
|
+
|
39
|
+
### Passing down sidekiq options
|
40
|
+
|
41
|
+
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.
|
42
|
+
|
43
|
+
### Passing down schedule options
|
44
|
+
|
45
|
+
In order be able to schedule jobs to be run in the future following [Scheduled Jobs](https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs) you can add `sidekiq_schedule_options` class method in your subscriber definition - those options will be passed to Sidekiq's `perform_in` method when the worker is called.
|
46
|
+
|
47
|
+
This feature is not as powerful as Sidekiq's API that allows you to set this on every job enqueue, in this case you're able to set this for the hole listener class like:
|
48
|
+
```ruby
|
49
|
+
class MyListener
|
50
|
+
#...
|
51
|
+
|
52
|
+
def self.sidekiq_schedule_options
|
53
|
+
{ perform_in: 5 }
|
54
|
+
end
|
55
|
+
|
56
|
+
#...
|
57
|
+
end
|
58
|
+
```
|
59
|
+
Or you can set this per event (method called on the listener), like so:
|
60
|
+
```ruby
|
61
|
+
class MyListener
|
62
|
+
#...
|
63
|
+
|
64
|
+
def self.sidekiq_schedule_options
|
65
|
+
{ event_name: { perform_in: 5 } }
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.event_name
|
69
|
+
#...
|
70
|
+
end
|
71
|
+
|
72
|
+
#...
|
73
|
+
end
|
74
|
+
```
|
75
|
+
In both cases there is also available the `perform_at` option.
|
76
|
+
|
77
|
+
## Running Specs
|
78
|
+
|
79
|
+
Redis needs to be running. If you don't have an instance of redis on your machine, you can use the provided `docker-compose.yml`:
|
80
|
+
|
81
|
+
```
|
82
|
+
docker compose up -d
|
83
|
+
```
|
84
|
+
|
85
|
+
You also need to be running sidekiq via `scripts/sidekiq`:
|
86
|
+
|
87
|
+
```
|
88
|
+
scripts/sidekiq
|
89
|
+
```
|
90
|
+
|
91
|
+
Finally:
|
92
|
+
|
93
|
+
```
|
94
|
+
bundle exec rspec
|
95
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'wisper'
|
3
|
+
require 'sidekiq'
|
4
|
+
require 'wisper/sidekiq/version'
|
5
|
+
|
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
|
+
|
12
|
+
class SidekiqBroadcaster
|
13
|
+
class Worker
|
14
|
+
include ::Sidekiq::Worker
|
15
|
+
|
16
|
+
def perform(yml)
|
17
|
+
(subscriber, event, args) =
|
18
|
+
if Psych::VERSION.to_i >= 4
|
19
|
+
::YAML.unsafe_load(yml)
|
20
|
+
else
|
21
|
+
::YAML.load(yml)
|
22
|
+
end
|
23
|
+
subscriber.public_send(event, *args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.register
|
28
|
+
Wisper.configure do |config|
|
29
|
+
config.broadcaster :sidekiq, SidekiqBroadcaster.new
|
30
|
+
config.broadcaster :async, SidekiqBroadcaster.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def broadcast(subscriber, _publisher, event, *args, **_kwargs)
|
35
|
+
options = sidekiq_options(subscriber)
|
36
|
+
schedule_options = sidekiq_schedule_options(subscriber, event)
|
37
|
+
|
38
|
+
Worker.set(options).perform_in(
|
39
|
+
schedule_options.fetch(:delay, 0),
|
40
|
+
::YAML.dump([subscriber, event, args])
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def sidekiq_options(subscriber)
|
47
|
+
subscriber.respond_to?(:sidekiq_options) ? subscriber.sidekiq_options : {}
|
48
|
+
end
|
49
|
+
|
50
|
+
def sidekiq_schedule_options(subscriber, event)
|
51
|
+
return {} unless subscriber.respond_to?(:sidekiq_schedule_options)
|
52
|
+
|
53
|
+
options = subscriber.sidekiq_schedule_options
|
54
|
+
|
55
|
+
if options.has_key?(event.to_sym)
|
56
|
+
delay_option(options[event.to_sym])
|
57
|
+
else
|
58
|
+
delay_option(options)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def delay_option(options)
|
63
|
+
return {} unless options.key?(:perform_in) || options.key?(:perform_at)
|
64
|
+
|
65
|
+
{ delay: options[:perform_in] || options[:perform_at] }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
Wisper::SidekiqBroadcaster.register
|
data/scripts/sidekiq
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'wisper/sidekiq'
|
2
|
+
|
3
|
+
RSpec.describe 'configuration' do
|
4
|
+
let(:configuration) { Wisper.configuration }
|
5
|
+
|
6
|
+
it 'configures sidekiq as a broadcaster' do
|
7
|
+
expect(configuration.broadcasters).to include :sidekiq
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'configures sidekiq as default async broadcaster' do
|
11
|
+
expect(configuration.broadcasters[:async]).to be_an_instance_of(Wisper::SidekiqBroadcaster)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'wisper/sidekiq'
|
2
|
+
|
3
|
+
require_relative 'dummy_app/app'
|
4
|
+
require 'sidekiq/api'
|
5
|
+
|
6
|
+
RSpec.describe 'integration tests:' do
|
7
|
+
let(:publisher) do
|
8
|
+
Class.new do
|
9
|
+
include Wisper::Publisher
|
10
|
+
|
11
|
+
def run
|
12
|
+
broadcast(:it_happened, { hello: 'world' })
|
13
|
+
end
|
14
|
+
end.new
|
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
|
25
|
+
|
26
|
+
before do
|
27
|
+
Sidekiq::Testing.disable!
|
28
|
+
Sidekiq::Queue.new.clear
|
29
|
+
Sidekiq::RetrySet.new.clear
|
30
|
+
File.delete('/tmp/shared') if File.exist?('/tmp/shared')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'performs event in a different process' do
|
34
|
+
publisher.subscribe(Subscriber, async: Wisper::SidekiqBroadcaster.new)
|
35
|
+
publisher.run
|
36
|
+
ensure_sidekiq_was_running
|
37
|
+
|
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
|
45
|
+
|
46
|
+
expect(shared_content).to include('{:hello=>"world"}')
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'sidekiq/testing'
|
2
|
+
|
3
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
4
|
+
YAML::ENGINE.yamler = 'psych'
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.expect_with :rspec do |expectations|
|
9
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
10
|
+
end
|
11
|
+
|
12
|
+
config.mock_with :rspec do |mocks|
|
13
|
+
mocks.verify_partial_doubles = true
|
14
|
+
end
|
15
|
+
|
16
|
+
config.filter_run :focus
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
|
19
|
+
config.disable_monkey_patching!
|
20
|
+
|
21
|
+
config.warnings = true
|
22
|
+
|
23
|
+
if config.files_to_run.one?
|
24
|
+
config.default_formatter = 'doc'
|
25
|
+
end
|
26
|
+
|
27
|
+
config.profile_examples = 0
|
28
|
+
|
29
|
+
config.order = :random
|
30
|
+
|
31
|
+
Kernel.srand config.seed
|
32
|
+
end
|
@@ -0,0 +1,162 @@
|
|
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
|
+
class CustomizedScheduleInJobSubscriberUnderTest
|
27
|
+
def self.it_happened
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.sidekiq_schedule_options
|
31
|
+
{ perform_in: 5 }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class CustomizedEventScheduleInJobSubscriberUnderTest
|
36
|
+
def self.it_happened
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.sidekiq_schedule_options
|
40
|
+
{ it_happened: { perform_in: 5 } }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class CustomizedScheduleAtJobSubscriberUnderTest
|
45
|
+
def self.it_happened
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.sidekiq_schedule_options
|
49
|
+
{ perform_at: Time.now + 5 }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class CustomizedEventScheduleAtJobSubscriberUnderTest
|
54
|
+
def self.it_happened
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.sidekiq_schedule_options
|
58
|
+
{ it_happened: { perform_at: Time.now + 5 } }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class CustomizedBadScheduleInJobSubscriberUnderTest
|
63
|
+
def self.it_happened
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.sidekiq_schedule_options
|
67
|
+
{ perform_in: 'not a number', delay: 5 }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class CustomizedBadDefaultScheduleInWithEventScheduleAtJobSubscriberUnderTest
|
72
|
+
def self.it_happened
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.sidekiq_schedule_options
|
76
|
+
{ perform_in: 'not a number', delay: 5, it_happened: { perform_at: Time.now + 5 } }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:publisher) { PublisherUnderTest.new }
|
81
|
+
|
82
|
+
before { Sidekiq::Testing.fake! }
|
83
|
+
after { Sidekiq::Testing.disable! }
|
84
|
+
|
85
|
+
describe '#broadcast' do
|
86
|
+
it 'schedules a sidekiq job' do
|
87
|
+
publisher.subscribe(RegularSubscriberUnderTest, async: described_class.new)
|
88
|
+
|
89
|
+
expect { publisher.run }
|
90
|
+
.to change(Sidekiq::Queues["default"], :size).by(1)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'schedules to run in some time a sidekiq job' do
|
94
|
+
publisher.subscribe(CustomizedScheduleInJobSubscriberUnderTest, async: described_class.new)
|
95
|
+
|
96
|
+
# In order to look into Sidekiq::ScheduledSet we need to hit redis
|
97
|
+
expect { publisher.run }
|
98
|
+
.to change { Sidekiq::Queues["default"].select{|job| job.key?('at')}.size }.by(1)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'schedules to run in some time a sidekiq job for an event' do
|
102
|
+
publisher.subscribe(CustomizedEventScheduleInJobSubscriberUnderTest, async: described_class.new)
|
103
|
+
|
104
|
+
# In order to look into Sidekiq::ScheduledSet we need to hit redis
|
105
|
+
expect { publisher.run }
|
106
|
+
.to change { Sidekiq::Queues["default"].select{|job| job.key?('at')}.size }.by(1)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'schedules to run at some time a sidekiq job' do
|
110
|
+
publisher.subscribe(CustomizedEventScheduleAtJobSubscriberUnderTest, async: described_class.new)
|
111
|
+
|
112
|
+
# In order to look into Sidekiq::ScheduledSet we need to hit redis
|
113
|
+
expect { publisher.run }
|
114
|
+
.to change { Sidekiq::Queues["default"].select{|job| job.key?('at')}.size }.by(1)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'schedules to run at some time a sidekiq job for an event' do
|
118
|
+
publisher.subscribe(CustomizedEventScheduleInJobSubscriberUnderTest, async: described_class.new)
|
119
|
+
|
120
|
+
# In order to look into Sidekiq::ScheduledSet we need to hit redis
|
121
|
+
expect { publisher.run }
|
122
|
+
.to change { Sidekiq::Queues["default"].select{|job| job.key?('at')}.size }.by(1)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'can respect custom sidekiq_options' do
|
126
|
+
publisher.subscribe(CustomizedSubscriberUnderTest, async: described_class.new)
|
127
|
+
|
128
|
+
expect { publisher.run }
|
129
|
+
.to change(Sidekiq::Queues["my_queue"], :size).by(1)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'schedules a sidekiq job with bad sidekiq_schedule_options' do
|
133
|
+
publisher.subscribe(CustomizedBadScheduleInJobSubscriberUnderTest, async: described_class.new)
|
134
|
+
|
135
|
+
expect { publisher.run }
|
136
|
+
.to change(Sidekiq::Queues["default"], :size).by(1)
|
137
|
+
expect { publisher.run }
|
138
|
+
.not_to change { Sidekiq::Queues["default"].select{|job| job.key?('at')}.size }
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'schedules a sidekiq job with bad sidekiq_schedule_options' do
|
142
|
+
publisher.subscribe(CustomizedBadDefaultScheduleInWithEventScheduleAtJobSubscriberUnderTest, async: described_class.new)
|
143
|
+
|
144
|
+
expect { publisher.run }
|
145
|
+
.to change { Sidekiq::Queues["default"].select{|job| job.key?('at')}.size }.by(1)
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when provides subscriber with args' do
|
149
|
+
let(:subscriber) { RegularSubscriberUnderTest }
|
150
|
+
let(:event) { 'it_happened' }
|
151
|
+
let(:args) { [1,2,3] }
|
152
|
+
|
153
|
+
subject(:broadcast_event) { described_class.new.broadcast(subscriber, nil, event, *args) }
|
154
|
+
|
155
|
+
it 'subscriber receives event with corrects args' do
|
156
|
+
expect(RegularSubscriberUnderTest).to receive(event).with(*args)
|
157
|
+
|
158
|
+
Sidekiq::Testing.inline! { broadcast_event }
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wisper/sidekiq/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wisper-sidekiq-compat"
|
8
|
+
spec.version = Wisper::Sidekiq::VERSION
|
9
|
+
spec.authors = ["Kris Leech", "Jamie Schembri"]
|
10
|
+
spec.email = ["kris.leech@gmail.com", "jamie.schembri@nedap.com"]
|
11
|
+
spec.summary = 'Async publishing for Wisper using Sidekiq'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/nedap/wisper-sidekiq-compat"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 3.0'
|
22
|
+
spec.add_dependency 'wisper-compat'
|
23
|
+
spec.add_dependency 'sidekiq', '>= 6.5', '< 7'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wisper-sidekiq-compat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kris Leech
|
8
|
+
- Jamie Schembri
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: wisper-compat
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sidekiq
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '6.5'
|
35
|
+
- - "<"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '7'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '6.5'
|
45
|
+
- - "<"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '7'
|
48
|
+
description: Async publishing for Wisper using Sidekiq
|
49
|
+
email:
|
50
|
+
- kris.leech@gmail.com
|
51
|
+
- jamie.schembri@nedap.com
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- ".github/workflows/test.yml"
|
57
|
+
- ".gitignore"
|
58
|
+
- ".rspec"
|
59
|
+
- ".ruby-version"
|
60
|
+
- CHANGELOG.md
|
61
|
+
- Gemfile
|
62
|
+
- LICENSE.txt
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- docker-compose.yml
|
66
|
+
- lib/wisper/sidekiq.rb
|
67
|
+
- lib/wisper/sidekiq/version.rb
|
68
|
+
- scripts/sidekiq
|
69
|
+
- spec/configuration_spec.rb
|
70
|
+
- spec/dummy_app/app.rb
|
71
|
+
- spec/dummy_app/subscriber.rb
|
72
|
+
- spec/integration_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/wisper/sidekiq_broadcaster_spec.rb
|
75
|
+
- wisper-sidekiq-compat.gemspec
|
76
|
+
homepage: https://github.com/nedap/wisper-sidekiq-compat
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.4.6
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Async publishing for Wisper using Sidekiq
|
99
|
+
test_files:
|
100
|
+
- spec/configuration_spec.rb
|
101
|
+
- spec/dummy_app/app.rb
|
102
|
+
- spec/dummy_app/subscriber.rb
|
103
|
+
- spec/integration_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/wisper/sidekiq_broadcaster_spec.rb
|