Rekiq is a recurring worker extension for Sidekiq.
Rekiq extends Sidekiq and adds functionality to schedule recurring workers.
Sidekiq is an amazing gem that allows us to execute work asynchronously, or even schedule work to be run at a given time. Now, wouldn't it be nice if it also allowed us to schedule a worker to do recurring work? That's the purpose of rekiq.
For example, rekiq allows you to schedule a worker to repeat the same work every friday at 23:00.
Tested with:
-
ruby 2.2.0, 2.1.1, 2.0.0
-
sidekiq 3.3.3
Add this line to your application's Gemfile:
gem 'rekiq'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rekiq
-
Require rekiq after sidekiq:
require 'sidekiq' require 'rekiq'
-
We need a 'schedule' object (responsible for returning the time at which the worker should start) which must respond to method next_occurrence and receives one argument of type Time (more at The schedule object). For our example we'll be using the gem ice_cube (don't forget to require it):
# define worker as normal class ExampleWorker include Sidekiq::Worker def perform(arg1, arg2) # Do some work end end # create schedule for worker to repeat every friday at 2am schedule = IceCube::Schedule.new do |s| s.rrule IceCube::Rule.daily.day(:friday).hour_of_day(2) end # now just start your worker ExampleWorker.perform_recurringly(schedule, 'argument_1', 'argument_2')
And that's it! Now the worker will run every friday as 2am.
You can use your own schedule object, configure worker to schedule before or after work is done, set a margin, and much more! So please feel free to check wiki for more details.
- Fork it ( https://github.com/junhanamaki/rekiq/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request