Sidekiq has been my favorite tool for setting up background processing in Ruby on Rails applications. Mainly I use it for delivering emails, update data inside tables & much more… and it can take a little effort to get up and running every day in exact time on i.e. Heroku.
I have worked with Heroku Scheduler jobs but I have found some issues which explained their documentation that’s why I’m using Sidekiq Scheduler.
Follow the below steps:
gem install sidekiq-scheduler
or you can use your Gemfile
gem 'sidekiq', '~> 3.3.0'
# sidekiq scheduler
gem 'sidekiq-scheduler', '~> 1'
Then create a folder inside app directory which name “workers”.
Create a file inside workers folder like “hello_world.rb”.
#app/workers/helo_world.rb class HelloWorld include Sidekiq::worker def perform #=> you can write anything based on your action like 'send_email' or 'newslatter' etc ... puts 'Hello World' end end
Now you can go your config file
:schedule: hello_world: every: 1m # Runs once per minute class: HelloWorld
bundle exec sidekiq
Redis is required for sidekiq, install this on your Heroku app then past this on your Procfile same as below-
worker: bundle exec sidekiq -c 5 -v
Then push to your production.
Happy coding 🙂