siftery-wisper-sidekiq 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +2 -0
- data/lib/wisper/sidekiq.rb +27 -0
- data/lib/wisper/sidekiq/version.rb +5 -0
- data/scripts/sidekiq +5 -0
- data/siftery-wisper-sidekiq.gemspec +23 -0
- data/spec/configuration_spec.rb +14 -0
- data/spec/dummy_app/app.rb +3 -0
- data/spec/dummy_app/logs/.gitkeep +0 -0
- data/spec/dummy_app/subscriber.rb +7 -0
- data/spec/integration_spec.rb +58 -0
- data/spec/spec_helper.rb +37 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a6bf2c1b8f6afc160a2a2cf3b75a55e0b1469c9441483c5c4da6bf729f7554e9
|
4
|
+
data.tar.gz: 66e2a22308253a28bd0e9e6575f2f6aeaa3962dd8c9049d4dbb64c71ec907fca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 683d12a7865981d4f40d6376df6d8d7ead14d853b366724c30909a69fc3116440389c5124af825e8561905e72b7093ef56103e6cc1863e076863027a7c6601da
|
7
|
+
data.tar.gz: d610481429ec855fa991a01abfced5c11c03a2a5dfa6fe58d47629dcd019767e9e04e2748ae738c80e90c4e8180a6f3589262a0cc4c2f58836e8c5f080fea165
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
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-version
|
25
|
+
.ruby-gemset
|
data/.rspec
ADDED
data/.travis.yml
ADDED
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,67 @@
|
|
1
|
+
# Wisper::Sidekiq
|
2
|
+
|
3
|
+
Provides [Wisper](https://github.com/krisleech/wisper) with asynchronous event
|
4
|
+
publishing using [Sidekiq](https://github.com/mperham/sidekiq).
|
5
|
+
|
6
|
+
[](http://badge.fury.io/rb/wisper-sidekiq)
|
7
|
+
[](https://codeclimate.com/github/krisleech/wisper-sidekiq)
|
8
|
+
[](https://travis-ci.org/krisleech/wisper-sidekiq)
|
9
|
+
[](https://coveralls.io/r/krisleech/wisper-sidekiq?branch=master)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'wisper-sidekiq'
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
publisher.subscribe(MyListener, async: true)
|
21
|
+
```
|
22
|
+
|
23
|
+
The listener must be a class (or module), not an object. This is because Sidekiq
|
24
|
+
can not reconstruct the state of an object. However a class is easily reconstructed.
|
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
|
+
|
35
|
+
When publshing events the arguments must be simple as they need to be
|
36
|
+
serialized. For example instead of sending an `ActiveRecord` model as an argument
|
37
|
+
use its id instead.
|
38
|
+
|
39
|
+
See the [Sidekiq best practices](https://github.com/mperham/sidekiq/wiki/Best-Practices)
|
40
|
+
for more information.
|
41
|
+
|
42
|
+
## Advanced options
|
43
|
+
|
44
|
+
You can also customize queue name, retry value and other sidekiq options when registering the listener like the following:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
publisher.subscribe(MyListener, async: { queue: 'custom', retry: false })
|
48
|
+
```
|
49
|
+
|
50
|
+
## Compatibility
|
51
|
+
|
52
|
+
The same Ruby versions as Sidekiq are offically supported, but it should work
|
53
|
+
with any 2.x syntax Ruby including JRuby and Rubinius.
|
54
|
+
|
55
|
+
See the [build status](https://travis-ci.org/krisleech/wisper-sidekiq) for details.
|
56
|
+
|
57
|
+
## Running Specs
|
58
|
+
|
59
|
+
```
|
60
|
+
scripts/sidekiq
|
61
|
+
bundle exec rspec
|
62
|
+
```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
To run sidekiq use `scripts/sidekiq`. This wraps sidekiq in [rerun](https://github.com/alexch/rerun)
|
67
|
+
which will restart sidekiq when `specs/dummy_app` changes.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'wisper'
|
2
|
+
require 'sidekiq'
|
3
|
+
|
4
|
+
require 'wisper/sidekiq/version'
|
5
|
+
|
6
|
+
module Wisper
|
7
|
+
class SidekiqBroadcaster
|
8
|
+
attr_reader :options
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@options = options == true ? {} : options
|
12
|
+
end
|
13
|
+
|
14
|
+
def broadcast(subscriber, publisher, event, args)
|
15
|
+
subscriber.delay(options).public_send(event, *args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.register
|
19
|
+
Wisper.configure do |config|
|
20
|
+
config.broadcaster :sidekiq, Proc.new { |options| SidekiqBroadcaster.new(options) }
|
21
|
+
config.broadcaster :async, Proc.new { |options| SidekiqBroadcaster.new(options) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Wisper::SidekiqBroadcaster.register
|
data/scripts/sidekiq
ADDED
@@ -0,0 +1,23 @@
|
|
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 = "siftery-wisper-sidekiq"
|
8
|
+
spec.version = Wisper::Sidekiq::VERSION
|
9
|
+
spec.authors = ["Shubham Kumar"]
|
10
|
+
spec.email = ["shubh2336@gmail.com"]
|
11
|
+
spec.summary = 'Async publishing for Wisper using Sidekiq'
|
12
|
+
spec.description = 'Async publishing for Wisper using Sidekiq'
|
13
|
+
spec.homepage = "https://github.com/shubh2336/wisper-sidekiq"
|
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.add_dependency 'wisper'
|
22
|
+
spec.add_dependency 'sidekiq'
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
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 callable async broadcaster' do
|
11
|
+
expect(configuration.broadcasters[:async]).to be_an_instance_of(Proc)
|
12
|
+
expect(configuration.broadcasters[:async].call).to be_an_instance_of(Wisper::SidekiqBroadcaster)
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
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
|
+
|
17
|
+
before do
|
18
|
+
Sidekiq::Queue.new.clear
|
19
|
+
Sidekiq::RetrySet.new.clear
|
20
|
+
File.delete('/tmp/shared') if File.exist?('/tmp/shared')
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when broadcaster is plain object' do
|
24
|
+
it 'performs event in a different process' do
|
25
|
+
publisher.subscribe(Subscriber, async: Wisper::SidekiqBroadcaster.new)
|
26
|
+
|
27
|
+
publisher.run
|
28
|
+
|
29
|
+
Timeout.timeout(10) do
|
30
|
+
while !File.exist?('/tmp/shared')
|
31
|
+
sleep(0.1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
shared_content = File.read('/tmp/shared')
|
36
|
+
expect(shared_content).not_to eq "pid: #{Process.pid}\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when broadcaster is async and passes options' do
|
41
|
+
it 'performs event in a different process' do
|
42
|
+
pending('Pending until wisper support for async options is published')
|
43
|
+
|
44
|
+
publisher.subscribe(Subscriber, async: { queue: 'default' })
|
45
|
+
|
46
|
+
publisher.run
|
47
|
+
|
48
|
+
Timeout.timeout(10) do
|
49
|
+
while !File.exist?('/tmp/shared')
|
50
|
+
sleep(0.1)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
shared_content = File.read('/tmp/shared')
|
55
|
+
expect(shared_content).not_to eq "pid: #{Process.pid}\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
5
|
+
|
6
|
+
SimpleCov.start { add_filter 'spec/dummy_app' }
|
7
|
+
|
8
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
9
|
+
YAML::ENGINE.yamler = 'psych'
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.expect_with :rspec do |expectations|
|
14
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
15
|
+
end
|
16
|
+
|
17
|
+
config.mock_with :rspec do |mocks|
|
18
|
+
mocks.verify_partial_doubles = true
|
19
|
+
end
|
20
|
+
|
21
|
+
config.filter_run :focus
|
22
|
+
config.run_all_when_everything_filtered = true
|
23
|
+
|
24
|
+
config.disable_monkey_patching!
|
25
|
+
|
26
|
+
config.warnings = true
|
27
|
+
|
28
|
+
if config.files_to_run.one?
|
29
|
+
config.default_formatter = 'doc'
|
30
|
+
end
|
31
|
+
|
32
|
+
config.profile_examples = 0
|
33
|
+
|
34
|
+
config.order = :random
|
35
|
+
|
36
|
+
Kernel.srand config.seed
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: siftery-wisper-sidekiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shubham Kumar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: wisper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Async publishing for Wisper using Sidekiq
|
42
|
+
email:
|
43
|
+
- shubh2336@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/wisper/sidekiq.rb
|
56
|
+
- lib/wisper/sidekiq/version.rb
|
57
|
+
- scripts/sidekiq
|
58
|
+
- siftery-wisper-sidekiq.gemspec
|
59
|
+
- spec/configuration_spec.rb
|
60
|
+
- spec/dummy_app/app.rb
|
61
|
+
- spec/dummy_app/logs/.gitkeep
|
62
|
+
- spec/dummy_app/subscriber.rb
|
63
|
+
- spec/integration_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
homepage: https://github.com/shubh2336/wisper-sidekiq
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.0.3
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Async publishing for Wisper using Sidekiq
|
88
|
+
test_files:
|
89
|
+
- spec/configuration_spec.rb
|
90
|
+
- spec/dummy_app/app.rb
|
91
|
+
- spec/dummy_app/logs/.gitkeep
|
92
|
+
- spec/dummy_app/subscriber.rb
|
93
|
+
- spec/integration_spec.rb
|
94
|
+
- spec/spec_helper.rb
|