Dejavu is a clockless scheduler that uses Sidekiq's built-in scheduling
MIT License
Dejavu is a clockless scheduler that uses Sidekiq's built-in scheduling.
Most scheduling solutions for Sidekiq require either a separate cron like process or run an internal clock thread inside sidekiq server to manage schedules.
Dejavu uses Sidekiq's internal scheduling, like Sidekiq::Worker.perform_in
and Sidekiq::Worker.perform_at
so it doesn't need its own clock process/thread
and integrates nicely with Sidekiq without duplicating any functionality.
Scheduled jobs can be controlled through the Scheduled page in the Sidekiq::Web UI.
This is BETA quality code and doesn't yet have any specs, so make sure you test it well. Requires Sidekiq 3.0 or later. Compatibility with older versions could probably be added.
Warning aside, this code has run in production since October 2014 and has scheduled several million jobs without any issues. So if you want a very lightweight scheduler give it a shot.
Add this line to your application's Gemfile:
gem 'sidekiq-dejavu'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sidekiq-dejavu
You can configure schedule tasks in your config/sidekiq.yml:
:schedule:
hello_world:
interval: 10
class: HelloWorldWorker
queue: hello
retry: false
backtrace: false
args:
- Hello
- World
cleanup:
interval: '30 5 * * *' # every day at 5:30
class: HelloWorldWorker
queue: hello
retry: false
backtrace: false
args:
- Hello
- World
Interval can be specified in seconds or as a cron expression, including vixie cron syntax.
If a job fails or takes longer than an interval it will be retried at the next interval. In most cases you should set jour jobs to retry: false
to keep Sidekiq's retries from competing with the scheduled jobs.
You also need to set all options for the job, because currently a workers sidekiq_options
are ignored. The minium required options for a schedule are interval
and class
. The same worker can be scheduled multiple times by using different schedule names (keys) in the config.
Note that by default sidekiq polls scheduled jobs roughly every 15 seconds, which means in order to run jobs at shorter intervals youd'd have to tune config.average_scheduled_poll_interval
to a lower value.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)