Starting delayed_job at startup

In combination with the capistrano restart recipe it’s quite convenient to use cron to also start the delayed_job daemon at startup using the special @reboot time in a crontab:

@reboot /bin/bash -l -c 'cd /path/to/app && RAILS_ENV=production script/delayed_job restart'

And it’s even more convenient together with whenever to configure a scheduled task:

job_type :envcommand, 'cd :path && RAILS_ENV=:environment :task'

every :reboot do
  envcommand 'script/delayed_job restart'
end

Not sure if all implementation of cron actually only run @reboot at system startup but at least Ubuntu seams to only run them at start up and not whenever the cron daemon start or restart. If you pass restart to script/delayed_job it will probably work in either case.

Leave a Comment

tech