Start or ensure that Delayed Job runs when an application/server restarts

前端 未结 4 571
被撕碎了的回忆
被撕碎了的回忆 2020-12-28 20:27

We have to use delayed_job (or some other background-job processor) to run jobs in the background, but we\'re not allowed to change the boot scripts/boot-levels on the serve

4条回答
  •  别那么骄傲
    2020-12-28 20:43

    not great, but works

    disclaimer: I say not great because this causes a periodic restart, which for many will not be desirable. And simply trying to start can cause problems because the implementation of DJ can lock up the queue if duplicate instances are created.

    You could schedule cron tasks that run periodically to start the job(s) in question. Since DJ treats start commands as no-ops when the job is already running, it just works. This approach also takes care of the case where DJ dies for some reason other than a host restart.

    # crontab example 
    0 * * * * /bin/bash -l -c 'cd /var/your-app/releases/20151207224034 && RAILS_ENV=production bundle exec script/delayed_job --queue=default -i=1 restart'
    

    If you are using a gem like whenever this is pretty straightforward.

    every 1.hour do
      script "delayed_job --queue=default -i=1 restart"
      script "delayed_job --queue=lowpri -i=2 restart"
    end
    

提交回复
热议问题