/ sidekiq

Recurring Sidekiq jobs

In most of our apps, we probably need to execute few background tasks more often, like every 10 minutes, once a week, etc. For scheduling these jobs, we need a scheduler that can re-run these tasks on specified intervals.

There are few schedulers like whenever, resque-scheduler, rufus-scheduler, etc that can do the job. However, these gems are not compatible Sidekiq and with apps deployed on Heroku.

There are 2 ways to make it work on Heroku.

1/ Using Heroku Scheduler addon.

Steps:

i) Create sidekiq job.

ii) Create a rake task that will triggers that worker.

iii) In Heroku Scheduler addon, specify the rake task and the interval after which you want to run this job.

2/ Using sidetiq gem(I'll recommend this).

Sidetiq uses ice_cube gem which is used to create recurring events. Steps:

i) Include sidetiq gem in gemfile and run bundle install.

ii) In the sidekiq job, mention following line of code:

 include Sidetiq::Schedulable
 recurrence { weekly } # for weekly execution of this job.

and you are set to go.

For complex schedules and other configuration options, refer wiki page: https://github.com/tobiassvn/sidetiq/wiki