rails delayed jobs with "whenever" and "delayed_job_active_record"

1k views Asked by At

I have never worked on delayed jobs, trying first time.

I used whenever and delayed_job_active_record. for whenever I followed the instruction at whenever like

gem 'whenever', :require => false
command: wheneverize .

and added schedule.rb

every 2.minutes do
  runner "Page.save_daily_detail"  #Page is name of model, and save_daily_detail put some entries in database
end

than

whenever --update-crontab

For delayed_job_active_record

gem 'delayed_job_active_record'

commands:

rails generate delayed_job:active_record
rake db:migrate

also in application.rb

config.active_job.queue_adapter = :delayed_job

and when I start jobs with

bundle exec rake jobs:work

it says that jobs start but does nothing. what 'm I missing here?

1

There are 1 answers

1
Satishakumar Awati On

You missed to restart crontab.

whenever --update-crontab <xyz_anyname> --set 'environment=production' #update crontab by passing environment
service crond restart # to restart crontab to reflect changes in Linux system

Only on linux answer works

Add this line in schedule.rb

ENV['RAILS_ENV'] = "#{@pre_set_variables[:environment]}"

While updating crontab pass environment variable accordingly in local and production.