How can we implement Cron Job using sidekiq-cron on heroku for production

491 Views Asked by At

config/schedule.yml

my_first_job: cron: "*/5 * * * *" class: "HardWorker" queue: hard_worker

second_job: cron: "*/30 * * * *" # execute at every 30 minutes class: "HardWorker" queue: hard_worker_long args: hard: "stuff"

1

There are 1 best solutions below

0
N. Maina On

Have you added a sidekiq initializer that loads the file if it exists. You can use the YAML.load

Example

# config/initializers/sidekiq.rb
cron_schedule_file = 'config/cron_schedule.yml'

if File.exist?(cron_schedule_file) && Sidekiq.server?
  Sidekiq::Cron::Job.load_from_hash YAML.load_file(cron_schedule_file)
end