sidekiq-corral 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +14 -0
- data/.streerc +2 -0
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +129 -0
- data/Rakefile +19 -0
- data/lib/sidekiq/corral/version.rb +7 -0
- data/lib/sidekiq/corral.rb +66 -0
- data/sig/sidekiq/corral.rbs +6 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b439de1e2bbdf25862994d714547b2f5f33a1e44ab7d95129a2635537a1efa4
|
4
|
+
data.tar.gz: 5c7580ca96ec6d8b94eef39b7aaae766182fdf7b6f486628e329de8d3946e14e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d9b1923a16971cc9ad0a185d435a48ba43baed28b401e57c092e6686ed21dbe0cbde308a0c2ece0ec0e556ca5fb19c3782f3151cb791f6fa735dcfdcde515b2
|
7
|
+
data.tar.gz: 4275fa4e6f59f422ce8627c98fd23d2ece312e20895c31459eed20fa3f5f23b09f8e6156a4724b9f5c927251c40691cd4a72ec08f1ff1b84beffcabd9808c19b
|
data/.rubocop.yml
ADDED
data/.streerc
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mo@molawson.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Mo Lawson
|
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,129 @@
|
|
1
|
+
# Sidekiq::Corral
|
2
|
+
|
3
|
+
A [Sidekiq](https://github.com/sidekiq/sidekiq) add-on that makes it easy to keep the processing for a job and all of the jobs it enqueues on a single queue.
|
4
|
+
|
5
|
+
## But Why?
|
6
|
+
Imagine a situation where you need to introduce a new Sidekiq job to do a specific task. But because you're working with a good bit of data, you split up the work into a bunch of small, idempotent jobs, as Sidekiq suggests. And you even go a step further, putting this new job class on its own queue to avoid clogging up one of your standard queues with these specialized jobs.
|
7
|
+
|
8
|
+
But these new jobs hardly ever live in isolation. In your existing application you're probably enqueuing jobs from a wide variety of places. And that's great until you realize that your new job enqueues a handful of these preexisting jobs based on lifecycle events or something else a few call sites away from the new job itself. This can quickly lead to a situation where the new jobs are on their own queue, as you intended, but as you churn through enough of them, the other jobs they enqueue start to fill up your other queues!
|
9
|
+
|
10
|
+
Wouldn't it be nice to be able to tell a job that not only does it go on a certain queue, but any other job that's enqueued while it's being processed should _also_ go on that same queue, ensuring that all work related to the initial job is processed separately from the other jobs in your application?
|
11
|
+
|
12
|
+
That's exactly where Sidekiq::Corral comes in!
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
17
|
+
|
18
|
+
Install the gem and add to the application's Gemfile by executing:
|
19
|
+
|
20
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
21
|
+
|
22
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
23
|
+
|
24
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
25
|
+
|
26
|
+
Install the middleware on application boot (e.g. in a Rails initializer or wherever you're configuring other parts of Sidekiq):
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# config/initializers/sidekiq.rb
|
30
|
+
|
31
|
+
Sidekiq::Corral.install
|
32
|
+
```
|
33
|
+
|
34
|
+
This will register the included middleware in the right spots.
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
### Sidekiq::Job.set
|
39
|
+
Set the corral when enqueueing a job:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
SomeJob.set(corral: "backfill").perform_async(args)
|
43
|
+
```
|
44
|
+
|
45
|
+
This will both set the corral and the queue for that job and any job enqueued during processing of that `SomeJob` instance.
|
46
|
+
|
47
|
+
### Sidekiq::Corral.confine
|
48
|
+
If you're enqueueing multiple jobs or calling classes that enqueue jobs of their own and you want to confine everything to a single queue, you can use `Sidekiq::Corral.confine`:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Sidekiq::Corral.confne("backfill") do
|
52
|
+
SomeJob.perform_async(args)
|
53
|
+
ClassThatEnqueuesJobs.new.call(more_args)
|
54
|
+
AnotherJob.peform_async(even_more_args)
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
All jobs enqueued within that block (including those enqueued in `ClassThatEnqueuesJobs`, etc.) will be put in the `"backfill"` corral and processed on the `"backfill"` queue.
|
59
|
+
|
60
|
+
|
61
|
+
### Exempt Queues
|
62
|
+
|
63
|
+
Sometimes a queue is special enough that you always want jobs destined for it to _always_ be processed there, regardless of Sidekiq::Corral's concerns. You can name those queues on setup:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Sidekiq::Corral.install(exempt_queues: ["notifications"])
|
67
|
+
```
|
68
|
+
|
69
|
+
Doing this will ensure anything destined for the `"notifications"` queue will be processed there. But those jobs will still pass along the corral set either on the job or further up the chain. So any jobs enqueued while it's processing will use the corral.
|
70
|
+
|
71
|
+
For example, given this set of jobs:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
class NormalJob
|
75
|
+
include Sidekiq::Job
|
76
|
+
sidekiq_options queue: "default"
|
77
|
+
|
78
|
+
def perform
|
79
|
+
SpecialJob.perform_async
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class SpecialJob
|
84
|
+
include Sidekiq::Job
|
85
|
+
sidekiq_options queue: "notifications"
|
86
|
+
|
87
|
+
def peform
|
88
|
+
AnotherNormalJob.perform_async
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class AnotherNormalJob
|
93
|
+
include Sidekiq::Job
|
94
|
+
sidekiq_options queue: "default"
|
95
|
+
|
96
|
+
def perform
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
Enqueuing the NormalJob with a corral would get processed like so:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
NormalJob.set(corral: "backfill").perform_async
|
105
|
+
|
106
|
+
NormalJob # queue: "backfill". corral: "backfill"
|
107
|
+
-> SpecialJob # queue: "notifications" corral: "backfill"
|
108
|
+
-> AnotherNormalJob # queue: "backfill" corral: "backfill"
|
109
|
+
```
|
110
|
+
|
111
|
+
|
112
|
+
## Development
|
113
|
+
|
114
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
115
|
+
|
116
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
117
|
+
|
118
|
+
## Contributing
|
119
|
+
|
120
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/molawson/sidekiq-corral. 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/molawson/sidekiq-corral/blob/main/CODE_OF_CONDUCT.md).
|
121
|
+
|
122
|
+
## License
|
123
|
+
|
124
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
125
|
+
|
126
|
+
## Code of Conduct
|
127
|
+
|
128
|
+
Everyone interacting in the Sidekiq::Corral project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/molawson/sidekiq-corral/blob/main/CODE_OF_CONDUCT.md).
|
129
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
require "syntax_tree/rake_tasks"
|
16
|
+
SyntaxTree::Rake::CheckTask.new
|
17
|
+
SyntaxTree::Rake::WriteTask.new
|
18
|
+
|
19
|
+
task default: %i[test]
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sidekiq"
|
4
|
+
|
5
|
+
require_relative "corral/version"
|
6
|
+
|
7
|
+
module Sidekiq
|
8
|
+
module Corral
|
9
|
+
class Error < StandardError
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def confine(queue)
|
14
|
+
orig_queue = current
|
15
|
+
self.current = queue
|
16
|
+
yield
|
17
|
+
ensure
|
18
|
+
self.current = orig_queue
|
19
|
+
end
|
20
|
+
|
21
|
+
def current
|
22
|
+
Thread.current[:sidekiq_corral_queue]
|
23
|
+
end
|
24
|
+
|
25
|
+
def install(opts = {})
|
26
|
+
Sidekiq.configure_client do |config|
|
27
|
+
config.client_middleware { |chain| chain.add(Sidekiq::Corral::Client, opts) }
|
28
|
+
end
|
29
|
+
|
30
|
+
Sidekiq.configure_server do |config|
|
31
|
+
config.server_middleware { |chain| chain.add(Sidekiq::Corral::Server) }
|
32
|
+
config.client_middleware { |chain| chain.add(Sidekiq::Corral::Client, opts) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def current=(queue)
|
39
|
+
Thread.current[:sidekiq_corral_queue] = queue
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Client
|
44
|
+
include Sidekiq::ClientMiddleware
|
45
|
+
|
46
|
+
def initialize(opts)
|
47
|
+
opts = opts.transform_keys(&:to_s)
|
48
|
+
@exempt_queues = Array(opts["exempt_queues"]).map(&:to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
def call(_worker_class, job, _queue, _redis_pool)
|
52
|
+
job["corral"] = Corral.current if Corral.current
|
53
|
+
job["queue"] = job["corral"] if job["corral"] && !@exempt_queues.include?(job["queue"])
|
54
|
+
yield
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Server
|
59
|
+
include Sidekiq::ServerMiddleware
|
60
|
+
|
61
|
+
def call(_worker, job, _queue, &block)
|
62
|
+
job["corral"] ? Corral.confine(job["corral"], &block) : block.call
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-corral
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mo Lawson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-24 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
|
+
description: Send a job to a queue and move all jobs it triggers to that same queue.
|
28
|
+
email:
|
29
|
+
- mo@molawson.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rubocop.yml"
|
35
|
+
- ".streerc"
|
36
|
+
- CHANGELOG.md
|
37
|
+
- CODE_OF_CONDUCT.md
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/sidekiq/corral.rb
|
42
|
+
- lib/sidekiq/corral/version.rb
|
43
|
+
- sig/sidekiq/corral.rbs
|
44
|
+
homepage: https://github.com/molawson/sidekiq-corral
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata:
|
48
|
+
allowed_push_host: https://rubygems.org
|
49
|
+
rubygems_mfa_required: 'true'
|
50
|
+
homepage_uri: https://github.com/molawson/sidekiq-corral
|
51
|
+
source_code_uri: https://github.com/molawson/sidekiq-corral
|
52
|
+
changelog_uri: https://github.com/molawson/sidekiq-corral/blob/main/CHANGELOG.md
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.7.0
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.4.10
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Confine a job and its child jobs to a single queue.
|
72
|
+
test_files: []
|