sidekiq-global_id 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +8 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +7 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/sidekiq/global_id.rb +12 -0
- data/lib/sidekiq/global_id/client_middleware.rb +18 -0
- data/lib/sidekiq/global_id/rspec.rb +18 -0
- data/lib/sidekiq/global_id/server_middleware.rb +16 -0
- data/sidekiq-global_id.gemspec +31 -0
- metadata +199 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 542565433c36e2b4b31292fd5ad06dfa0cb7e803
|
4
|
+
data.tar.gz: fbaea7575f98d205913d2e283920e65f8f2a7fa1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 257bea221617b5deebf139271ddc2189ee446a18a5cfd21dba35dedb1277391d1a2e359adfc86b0f195a50c6e1650bbc52768e608774c8841ae6ffea0a72c7fc
|
7
|
+
data.tar.gz: 27c1b23517701e659cda76a46fba133f37c9e4391ab3579f6b6ce261c45ae0402df3d9ad4bbd6b91846fc66797f574b9172aa4e39acc9ae70defded8677d14c2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Artem Bolshakov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/bolshakov/sidekiq-global_id.svg?branch=master)](https://travis-ci.org/bolshakov/sidekiq-global_id)
|
2
|
+
|
3
|
+
# Sidekiq::GlobalId
|
4
|
+
|
5
|
+
This gem provides Sidekiq middleware to serialize ActiveRecord objects with GlobalId. Actually it uses the same mechanism as
|
6
|
+
ActiveJob uses internally to serialize job arguments, and works not only with ActiveRecord objects, but also with Hashes.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'sidekiq-global_id'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install sidekiq-global_id
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Configure Sidekiq to use server and client middleware:
|
27
|
+
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Sidekiq.server_middleware do |chain|
|
31
|
+
chain.prepend Sidekiq::GlobalId::ServerMiddleware
|
32
|
+
end
|
33
|
+
|
34
|
+
Sidekiq.client_middleware do |chain|
|
35
|
+
chain.prepend Sidekiq::GlobalId::ClientMiddleware
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Now you can pass ActiveRecord arguments into Sidekiq worker:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
user = User.create!(params)
|
43
|
+
|
44
|
+
WelcomeEmailSender.perform_async(user)
|
45
|
+
```
|
46
|
+
|
47
|
+
## Testing
|
48
|
+
|
49
|
+
If you're using [rspec-sidekiq](https://github.com/philostler/rspec-sidekiq) gem, `require 'sidekiq/global_id/rspec'` to deserialize global ids:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'sidekiq/global_id/rspec'
|
53
|
+
|
54
|
+
it 'sends welcome email to user' do
|
55
|
+
WelcomeEmailSender.perform_async(user)
|
56
|
+
expect(WelcomeEmailSender).to have_enqueued_job(user)
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bolshakov/sidekiq-global_id.
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
74
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'sidekiq/globalid'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'globalid'
|
3
|
+
require 'active_job/arguments'
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
# Sidekiq and GlobalId integration
|
7
|
+
module GlobalId
|
8
|
+
autoload :Arguments, 'sidekiq/global_id/arguments'
|
9
|
+
autoload :ClientMiddleware, 'sidekiq/global_id/client_middleware'
|
10
|
+
autoload :ServerMiddleware, 'sidekiq/global_id/server_middleware'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module GlobalId
|
3
|
+
# Sidekiq client middleware serializes arguments before
|
4
|
+
# pushing job to Redis.
|
5
|
+
#
|
6
|
+
class ClientMiddleware
|
7
|
+
# @param _worker_class [Class<Sidekiq::Worker>]
|
8
|
+
# @param job [Hash] sidekiq job
|
9
|
+
# @param _queue [String]
|
10
|
+
# @param _redis_pool [ConnectionPool]
|
11
|
+
# @return [Hash] sidekiq job
|
12
|
+
def call(_worker_class, job, _queue, _redis_pool)
|
13
|
+
job['args'] = ActiveJob::Arguments.serialize(job['args'])
|
14
|
+
yield
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rspec/sidekiq/matchers/have_enqueued_job'
|
2
|
+
|
3
|
+
Sidekiq::Testing.server_middleware do |c|
|
4
|
+
c.prepend Sidekiq::GlobalId::ServerMiddleware
|
5
|
+
end
|
6
|
+
|
7
|
+
# Overrides rspec-sidekiq `have_enqueued_job` matcher to deserialize
|
8
|
+
# arguments.
|
9
|
+
class RSpec::Sidekiq::Matchers::HaveEnqueuedJob # rubocop:disable Style/ClassAndModuleChildren
|
10
|
+
private
|
11
|
+
|
12
|
+
def job_arguments(hash)
|
13
|
+
if hash.is_a?(Hash)
|
14
|
+
args = hash['arguments'] || hash['args']
|
15
|
+
ActiveJob::Arguments.deserialize(args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module GlobalId
|
3
|
+
# Sidekiq client middleware deserializes arguments before
|
4
|
+
# executing job.
|
5
|
+
class ServerMiddleware
|
6
|
+
# @param _worker [Sidekiq::Worker]
|
7
|
+
# @param job [Hash] sidekiq job
|
8
|
+
# @param _queue [String]
|
9
|
+
# @return [<any>] job args
|
10
|
+
def call(_worker, job, _queue)
|
11
|
+
job['args'] = ActiveJob::Arguments.deserialize(job['args'])
|
12
|
+
yield
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'sidekiq-global_id'
|
7
|
+
spec.version = '0.1'
|
8
|
+
spec.authors = ['Tema Bolshakov']
|
9
|
+
spec.email = ['abolshakov@spbtv.com']
|
10
|
+
|
11
|
+
spec.summary = 'Sidekiq and GlobalId integration'
|
12
|
+
spec.description = 'Provides Sidekiq middleware to serialize ActiveRecord objects with GlobalId'
|
13
|
+
spec.homepage = 'https://github.com/bolshakov/sidekiq-global_id'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'sidekiq', '>= 4.0'
|
22
|
+
spec.add_runtime_dependency 'globalid', '~> 0.3.7'
|
23
|
+
spec.add_runtime_dependency 'activejob', '>= 4.2.5'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
27
|
+
spec.add_development_dependency 'spbtv_code_style', '1.4.1'
|
28
|
+
spec.add_development_dependency 'temping', '~> 3.7.1'
|
29
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3.10'
|
30
|
+
spec.add_development_dependency 'rspec-sidekiq', '~> 2.2'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-global_id
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tema Bolshakov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sidekiq
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: globalid
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activejob
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.2.5
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.2.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: spbtv_code_style
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.4.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.4.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: temping
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.7.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.7.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sqlite3
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.3.10
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.3.10
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec-sidekiq
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '2.2'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '2.2'
|
153
|
+
description: Provides Sidekiq middleware to serialize ActiveRecord objects with GlobalId
|
154
|
+
email:
|
155
|
+
- abolshakov@spbtv.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rspec"
|
162
|
+
- ".rubocop.yml"
|
163
|
+
- ".travis.yml"
|
164
|
+
- Gemfile
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- bin/console
|
169
|
+
- bin/setup
|
170
|
+
- lib/sidekiq/global_id.rb
|
171
|
+
- lib/sidekiq/global_id/client_middleware.rb
|
172
|
+
- lib/sidekiq/global_id/rspec.rb
|
173
|
+
- lib/sidekiq/global_id/server_middleware.rb
|
174
|
+
- sidekiq-global_id.gemspec
|
175
|
+
homepage: https://github.com/bolshakov/sidekiq-global_id
|
176
|
+
licenses:
|
177
|
+
- MIT
|
178
|
+
metadata: {}
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubyforge_project:
|
195
|
+
rubygems_version: 2.5.1
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: Sidekiq and GlobalId integration
|
199
|
+
test_files: []
|