Sidekiq::Antidote
Installation
Add this line to your application’s Gemfile:
$ bundle add sidekiq-antidote
Or install it yourself as:
$ gem install sidekiq-antidote
Usage
require "sidekiq"
require "sidekiq/antidote"
Sidekiq::Antidote.configure do |config|
# Set inhibitors cache refresh rate in seconds.
# Default: 5.0
config.refresh_rate = 10.0
end
When running in forked environment (e.g., Puma web server), you also need to
call Sidekiq::Antidote.startup
on fork:
# file: config/puma.rb
on_worker_boot { Sidekiq::Antidote.startup }
Web UI
Adding Antidote tab in Sidekiq web UI is as simple as:
require "sidekiq/web"
require "sidekiq/antidote/web"
Middleware(s)
Sidekiq::Antidote
relies on following bundled middlewares:
-
Sidekiq::Antidote::Middlewares::Client
-
Sidekiq::Antidote::Middlewares::Server
The middleware is automatically injected when you require sidekiq/antidote
.
In rare cases, when this causes an issue, you can change middleware order manually:
Sidekiq.configure_client do |config|
# ...
config.client_middleware do |chain|
chain.prepend(Sidekiq::Antidote::Middlewares::Client)
end
end
Sidekiq.configure_server do |config|
# ...
config.client_middleware do |chain|
chain.prepend(Sidekiq::Antidote::Middlewares::Client)
end
config.server_middleware do |chain|
chain.prepend(Sidekiq::Antidote::Middlewares::Server)
end
end
Inhibitors
Treatments
When adding antidote you must pick on of the treatments:
- skip
-
Skip the job (don’t enqueue and/or perform)
- kill
-
Kill the job (send to the dead set instead of enqueueing and/or performing)
Class Qualifiers
Class qualifier is the job class pattern. It may match the job class or the job class and method name (when used with ActionMailer delayed deliveries):
-
ExampleJob
-
Namespaced::ExampleJob
-
UserMailer#welcome
You can also use pattern matching:
- *
-
Matches any number of alpha-numeric characters and underscores:
-
*Job
matches:ExampleJob
, but notNamespaced::ExampleJob
, orUserMailer#welcome
-
UserMailer#*
matches any method ofUserMailer
-
- **
-
Matches any number of components:
-
**
mathes any job or mailer method -
A::**::Job
matchesA::B::Job
,A::B::C::D::CJob
, etc. -
A**::Job
matchesA::Job
,Abc::Job
,A::B::Job
, etc.
-
- {}
-
Matches any of the given literal:
-
{A,B,C}Job
matchesAJob
,BJob
, andCJob
-
Compatibility
This library aims to support and is tested against:
If something doesn’t work on one of these versions, it’s a bug.
This library may inadvertently work (or seem to work) on other Ruby, Redis, and Sidekiq versions, however support will only be provided for the versions listed above.
If you would like this library to support another Ruby, Redis, or Sidekiq version, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby, Redis, and/or Sidekiq version may be dropped.
Development
bundle install bundle exec appraisal generate bundle exec appraisal install bundle exec rake
Contributing
-
Fork sidekiq-antidote
-
Make your changes
-
Ensure all tests pass (
bundle exec rake
) -
Send a merge request
-
If we like them we’ll merge them
-
If we’ve accepted a patch, feel free to ask for commit access!
Acknowledgement
-
Inspired by sidekiq-killswitch