How to Do Scheduling using Sidekiq Cron on Ruby on Rails

Sakti Wicaksono
Binar Academy
Published in
2 min readNov 20, 2018
Image from Unsplash

This is my first post, in this article, I’ll try to post how to schedulling using sidekiq-cron on ruby on rails.

  1. Before using sidekiq cron, you must install redis, in this section, i’m using Archlinux.
$ sudo pacman -S redis

2. Create new app, in this section, i’ll use postgresql.

$ rails new name_your_app -T --api --database=postgresql

3. Modify Gemfile and add :

gem 'redis'
gem 'sidekiq'
gem 'sidekiq-cron'

4. Install the gem.

$ bundle install

5. Generate the worker.

$ rails g sidekiq:worker Hard

6. Modify app/workers/hard_worker.rb, put something to do in perform(), example print “Hello World!”.

app/workers/hard_worker.rb

7. Modify config/schedule.yml.

config/schedule.yml

my_first_job is name for your job, you can change it freely and for class, choose class worker that you want to run on schedulling.

8. Modify config/initializers/sidekiq.rb.

config/initializers/sidekiq.rb

9. Run sidekiq to start schedulling.

$ sidekiq

10 . Done, every 1 minute it will print “Hello World!”.

11. If you got an error like this

try run redis-server, then do sidekiq again.

$ redis-server

Thanks and sorry for my bad english.

Source :

--

--