sidekiq-dry 1.0.0
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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +89 -0
- data/LICENSE.txt +21 -0
- data/README.md +143 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/sidekiq +29 -0
- data/lib/sidekiq/dry.rb +13 -0
- data/lib/sidekiq/dry/client/serialization_middleware.rb +24 -0
- data/lib/sidekiq/dry/server/deserialization_middleware.rb +31 -0
- data/lib/sidekiq/dry/version.rb +5 -0
- data/sidekiq-dry.gemspec +35 -0
- metadata +148 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 282e093e2f1d0697be874b0f58809fb355c1fa4f9fd4cac8ba582e1bf16c9b08
|
|
4
|
+
data.tar.gz: 2109bf98148d6a90a7f6f8779759244f5da82353b1f45bcb7ef36227167f0f1b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8c24e8f6d88e3f2b9e1a48aac40ffa8832080d99f7d61b3054a0a75f442d854b21f2e5c1debdd2488dd958faf374d0c47474fe70b8355530df797e73b7d66486
|
|
7
|
+
data.tar.gz: 722d24fa5c38df321abc9467d15910dc19aed1b935a75e15ad4f255253e48b9b5720be95c01900a82660e867e8dfd0c39c0db58351d109287ed6da8bf8adefd1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at dimitrisplusplus@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
sidekiq-dry (1.0.0)
|
|
5
|
+
activesupport
|
|
6
|
+
dry-struct (~> 1.0)
|
|
7
|
+
sidekiq (~> 6.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
activesupport (6.1.1)
|
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
14
|
+
i18n (>= 1.6, < 2)
|
|
15
|
+
minitest (>= 5.1)
|
|
16
|
+
tzinfo (~> 2.0)
|
|
17
|
+
zeitwerk (~> 2.3)
|
|
18
|
+
coderay (1.1.3)
|
|
19
|
+
concurrent-ruby (1.1.7)
|
|
20
|
+
connection_pool (2.2.3)
|
|
21
|
+
diff-lcs (1.4.4)
|
|
22
|
+
dry-configurable (0.12.0)
|
|
23
|
+
concurrent-ruby (~> 1.0)
|
|
24
|
+
dry-core (~> 0.5, >= 0.5.0)
|
|
25
|
+
dry-container (0.7.2)
|
|
26
|
+
concurrent-ruby (~> 1.0)
|
|
27
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
|
28
|
+
dry-core (0.5.0)
|
|
29
|
+
concurrent-ruby (~> 1.0)
|
|
30
|
+
dry-equalizer (0.3.0)
|
|
31
|
+
dry-inflector (0.2.0)
|
|
32
|
+
dry-logic (1.1.0)
|
|
33
|
+
concurrent-ruby (~> 1.0)
|
|
34
|
+
dry-core (~> 0.5, >= 0.5)
|
|
35
|
+
dry-struct (1.3.0)
|
|
36
|
+
dry-core (~> 0.4, >= 0.4.4)
|
|
37
|
+
dry-equalizer (~> 0.3)
|
|
38
|
+
dry-types (~> 1.3)
|
|
39
|
+
ice_nine (~> 0.11)
|
|
40
|
+
dry-types (1.4.0)
|
|
41
|
+
concurrent-ruby (~> 1.0)
|
|
42
|
+
dry-container (~> 0.3)
|
|
43
|
+
dry-core (~> 0.4, >= 0.4.4)
|
|
44
|
+
dry-equalizer (~> 0.3)
|
|
45
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
|
46
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
|
47
|
+
i18n (1.8.7)
|
|
48
|
+
concurrent-ruby (~> 1.0)
|
|
49
|
+
ice_nine (0.11.2)
|
|
50
|
+
method_source (1.0.0)
|
|
51
|
+
minitest (5.14.3)
|
|
52
|
+
pry (0.13.1)
|
|
53
|
+
coderay (~> 1.1)
|
|
54
|
+
method_source (~> 1.0)
|
|
55
|
+
rack (2.2.3)
|
|
56
|
+
rake (12.3.3)
|
|
57
|
+
redis (4.2.5)
|
|
58
|
+
rspec (3.10.0)
|
|
59
|
+
rspec-core (~> 3.10.0)
|
|
60
|
+
rspec-expectations (~> 3.10.0)
|
|
61
|
+
rspec-mocks (~> 3.10.0)
|
|
62
|
+
rspec-core (3.10.1)
|
|
63
|
+
rspec-support (~> 3.10.0)
|
|
64
|
+
rspec-expectations (3.10.1)
|
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
66
|
+
rspec-support (~> 3.10.0)
|
|
67
|
+
rspec-mocks (3.10.1)
|
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
69
|
+
rspec-support (~> 3.10.0)
|
|
70
|
+
rspec-support (3.10.1)
|
|
71
|
+
sidekiq (6.1.2)
|
|
72
|
+
connection_pool (>= 2.2.2)
|
|
73
|
+
rack (~> 2.0)
|
|
74
|
+
redis (>= 4.2.0)
|
|
75
|
+
tzinfo (2.0.4)
|
|
76
|
+
concurrent-ruby (~> 1.0)
|
|
77
|
+
zeitwerk (2.4.2)
|
|
78
|
+
|
|
79
|
+
PLATFORMS
|
|
80
|
+
ruby
|
|
81
|
+
|
|
82
|
+
DEPENDENCIES
|
|
83
|
+
pry
|
|
84
|
+
rake (~> 12.0)
|
|
85
|
+
rspec (~> 3.0)
|
|
86
|
+
sidekiq-dry!
|
|
87
|
+
|
|
88
|
+
BUNDLED WITH
|
|
89
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Dimitris Zorbas
|
|
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,143 @@
|
|
|
1
|
+
# Sidekiq::Dry
|
|
2
|
+
|
|
3
|
+
[](http://badge.fury.io/rb/sidekiq-dry)
|
|
4
|
+
[](https://travis-ci.org/zorbash/sidekiq-dry)
|
|
5
|
+
|
|
6
|
+
Gem to provide serialization and deserialization of [Dry::Struct][dry-struct]
|
|
7
|
+
arguments for [Sidekiq][sidekiq] jobs.
|
|
8
|
+
|
|
9
|
+
## Rationale
|
|
10
|
+
|
|
11
|
+
**Argument Validation**
|
|
12
|
+
|
|
13
|
+
By using `Dry::Struct` arguments you can choose to validate some attributes and mark
|
|
14
|
+
any of them as optional. An attempt to enqueue a job with invalid arguments will raise,
|
|
15
|
+
minimizing resource waste from jobs which would otherwise be retried multiple times without any chance of completing successfully.
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
class Coupons::ApplyCouponJob::Params < Dry::Struct
|
|
21
|
+
attribute :user_id, Types::Strict::Integer
|
|
22
|
+
attribute :coupon_code, Types::Strict::String
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
job_params = Coupons::ApplyCouponJob::Params.new(user_id: user.id, coupon_code: coupon.code)
|
|
26
|
+
|
|
27
|
+
Users::SendConfirmationEmailJob.perform_async(job_params)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Documentation**
|
|
31
|
+
|
|
32
|
+
Instead of documenting the types of each job argument, which can easily become outdated, you can refer to the types of the attributes of the struct.
|
|
33
|
+
|
|
34
|
+
**Positional Arguments are Error Prone**
|
|
35
|
+
|
|
36
|
+
You won't ever have to remember the order of arguments of a job.
|
|
37
|
+
|
|
38
|
+
**Versioning**
|
|
39
|
+
|
|
40
|
+
Adding this gem does not break any existing jobs in your app.
|
|
41
|
+
It only works on jobs enqueued with `Dry::Struct` objects.
|
|
42
|
+
|
|
43
|
+
Adding a new attribute to a parameter struct won't break already enqueued jobs.
|
|
44
|
+
|
|
45
|
+
It's trivial to version your structs using either a `version` attribute:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
class Coupons::ApplyCouponJob::Params < Dry::Struct
|
|
49
|
+
attribute :user_id, Types::Strict::Integer
|
|
50
|
+
attribute :coupon_code, Types::Strict::String
|
|
51
|
+
attribute :version, Types::Strict::String.default('1')
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
or versioned classes:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
class Coupons::ApplyCouponJob::Params::V1 < Dry::Struct
|
|
59
|
+
attribute :user_id, Types::Strict::Integer
|
|
60
|
+
attribute :coupon_code, Types::Strict::String
|
|
61
|
+
end
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
Add this line to your application's Gemfile:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
gem 'sidekiq-dry'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
And then execute:
|
|
73
|
+
|
|
74
|
+
$ bundle install
|
|
75
|
+
|
|
76
|
+
Configure Sidekiq to use the middlewares provided by this gem:
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
# File: config/initializers/sidekiq.rb
|
|
80
|
+
Sidekiq.configure_client do |config|
|
|
81
|
+
config.client_middleware do |chain|
|
|
82
|
+
chain.add Sidekiq::Dry::Client::SerializationMiddleware
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
Sidekiq.configure_server do |config|
|
|
87
|
+
config.server_middleware do |chain|
|
|
88
|
+
chain.add Sidekiq::Dry::Server::DeserializationMiddleware
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
See [Middleware usage](sidekiq-middlewares) on the Sidekiq wiki for more info.
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
**Enqueuing Jobs**
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
class Users::SendConfirmationEmailJob::Params < Dry::Struct
|
|
101
|
+
attribute :email, Types::Strict::String
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
job_params = Users::SendConfirmationEmailJob::Params.new(email: user.email)
|
|
105
|
+
|
|
106
|
+
Users::SendConfirmationEmailJob.perform_async(job_params)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Authoring Jobs**
|
|
110
|
+
|
|
111
|
+
```ruby
|
|
112
|
+
class Users::SendConfirmationEmailJob
|
|
113
|
+
include Sidekiq::Worker
|
|
114
|
+
|
|
115
|
+
def perform(params)
|
|
116
|
+
# params is an instance of Users::SendConfirmationEmailJob::Params
|
|
117
|
+
mail(to: params.email, subject: 'Welcome!')
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Development
|
|
123
|
+
|
|
124
|
+
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.
|
|
125
|
+
|
|
126
|
+
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).
|
|
127
|
+
|
|
128
|
+
## Contributing
|
|
129
|
+
|
|
130
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sidekiq-dry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sidekiq-dry/blob/master/CODE_OF_CONDUCT.md).
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
136
|
+
|
|
137
|
+
## Code of Conduct
|
|
138
|
+
|
|
139
|
+
Everyone interacting in the Sidekiq::Dry project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zorbash/sidekiq-dry/blob/master/CODE_OF_CONDUCT.md).
|
|
140
|
+
|
|
141
|
+
[dry-struct]: https://dry-rb.org/gems/dry-struct/1.0/
|
|
142
|
+
[sidekiq]: https://sidekiq.org/
|
|
143
|
+
[sidekiq-middlewares]: https://github.com/mperham/sidekiq/wiki/Middleware
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "sidekiq/dry"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/sidekiq
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'sidekiq' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "pathname"
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "rubygems"
|
|
27
|
+
require "bundler/setup"
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path("sidekiq", "sidekiq")
|
data/lib/sidekiq/dry.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'sidekiq'
|
|
4
|
+
require 'dry/struct'
|
|
5
|
+
require 'active_support/all'
|
|
6
|
+
|
|
7
|
+
require_relative 'dry/client/serialization_middleware'
|
|
8
|
+
require_relative 'dry/server/deserialization_middleware'
|
|
9
|
+
|
|
10
|
+
module Sidekiq
|
|
11
|
+
module Dry
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sidekiq
|
|
4
|
+
module Dry
|
|
5
|
+
module Client
|
|
6
|
+
# Middleware which converts `Dry::Struct` job arguments to hashes with a
|
|
7
|
+
# `_type` key to help deserializing back to the initial struct
|
|
8
|
+
class SerializationMiddleware
|
|
9
|
+
def call(_worker_class, job, _queue, _redis_pool)
|
|
10
|
+
job['args'].map! do |arg|
|
|
11
|
+
# Don't mutate non-struct arguments
|
|
12
|
+
next arg unless arg.is_a? ::Dry::Struct
|
|
13
|
+
|
|
14
|
+
# Set a `_type` argument to be able to instantiate
|
|
15
|
+
# the struct when the job is performed
|
|
16
|
+
arg.to_h.merge(_type: arg.class)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
yield
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sidekiq
|
|
4
|
+
module Dry
|
|
5
|
+
module Server
|
|
6
|
+
# Middleware which instantiates `Dry::Struct` hash arguments
|
|
7
|
+
class DeserializationMiddleware
|
|
8
|
+
def call(_worker, job, _queue)
|
|
9
|
+
job['args'].map! do |arg|
|
|
10
|
+
# Only mutate Dry::Struct hashes
|
|
11
|
+
next arg unless struct?(arg)
|
|
12
|
+
|
|
13
|
+
to_struct(arg)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
yield
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def struct?(arg)
|
|
22
|
+
arg.is_a?(Hash) && arg.key?('_type')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_struct(arg)
|
|
26
|
+
arg['_type'].constantize.new(arg.except('_type').symbolize_keys)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/sidekiq-dry.gemspec
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require_relative 'lib/sidekiq/dry/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "sidekiq-dry"
|
|
5
|
+
spec.version = Sidekiq::Dry::VERSION
|
|
6
|
+
spec.authors = ["Dimitris Zorbas"]
|
|
7
|
+
spec.email = ["dimitrisplusplus@gmail.com"]
|
|
8
|
+
|
|
9
|
+
spec.summary = %q{Dry::Struct arguments for Sidekiq jobs}
|
|
10
|
+
spec.description = %q{Gem to provide serialization and deserialization of Dry::Struct arguments for Sidekiq jobs}
|
|
11
|
+
spec.homepage = 'https://github.com/zorbash/sidekiq-dry'
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
|
14
|
+
|
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
16
|
+
spec.metadata["source_code_uri"] = 'https://github.com/zorbash/sidekiq-dry'
|
|
17
|
+
spec.metadata["changelog_uri"] = 'https://github.com/zorbash/sidekiq-dry/CHANGELOG.md'
|
|
18
|
+
|
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
23
|
+
end
|
|
24
|
+
spec.bindir = "exe"
|
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
26
|
+
spec.require_paths = ["lib"]
|
|
27
|
+
|
|
28
|
+
spec.add_dependency 'sidekiq', '~> 6.0'
|
|
29
|
+
spec.add_dependency 'dry-struct', '~> 1.0'
|
|
30
|
+
spec.add_dependency 'activesupport'
|
|
31
|
+
|
|
32
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
34
|
+
spec.add_development_dependency 'pry'
|
|
35
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sidekiq-dry
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dimitris Zorbas
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-01-11 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: '6.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '6.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: dry-struct
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: activesupport
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '12.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '12.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: pry
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: Gem to provide serialization and deserialization of Dry::Struct arguments
|
|
98
|
+
for Sidekiq jobs
|
|
99
|
+
email:
|
|
100
|
+
- dimitrisplusplus@gmail.com
|
|
101
|
+
executables: []
|
|
102
|
+
extensions: []
|
|
103
|
+
extra_rdoc_files: []
|
|
104
|
+
files:
|
|
105
|
+
- ".gitignore"
|
|
106
|
+
- ".rspec"
|
|
107
|
+
- ".travis.yml"
|
|
108
|
+
- CODE_OF_CONDUCT.md
|
|
109
|
+
- Gemfile
|
|
110
|
+
- Gemfile.lock
|
|
111
|
+
- LICENSE.txt
|
|
112
|
+
- README.md
|
|
113
|
+
- Rakefile
|
|
114
|
+
- bin/console
|
|
115
|
+
- bin/setup
|
|
116
|
+
- bin/sidekiq
|
|
117
|
+
- lib/sidekiq/dry.rb
|
|
118
|
+
- lib/sidekiq/dry/client/serialization_middleware.rb
|
|
119
|
+
- lib/sidekiq/dry/server/deserialization_middleware.rb
|
|
120
|
+
- lib/sidekiq/dry/version.rb
|
|
121
|
+
- sidekiq-dry.gemspec
|
|
122
|
+
homepage: https://github.com/zorbash/sidekiq-dry
|
|
123
|
+
licenses:
|
|
124
|
+
- MIT
|
|
125
|
+
metadata:
|
|
126
|
+
homepage_uri: https://github.com/zorbash/sidekiq-dry
|
|
127
|
+
source_code_uri: https://github.com/zorbash/sidekiq-dry
|
|
128
|
+
changelog_uri: https://github.com/zorbash/sidekiq-dry/CHANGELOG.md
|
|
129
|
+
post_install_message:
|
|
130
|
+
rdoc_options: []
|
|
131
|
+
require_paths:
|
|
132
|
+
- lib
|
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: 2.3.0
|
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
|
+
requirements:
|
|
140
|
+
- - ">="
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '0'
|
|
143
|
+
requirements: []
|
|
144
|
+
rubygems_version: 3.1.4
|
|
145
|
+
signing_key:
|
|
146
|
+
specification_version: 4
|
|
147
|
+
summary: Dry::Struct arguments for Sidekiq jobs
|
|
148
|
+
test_files: []
|