job going into a busy loop when lodging second task

I am running delayed_job for a few background services, all of which, until recently, run in isolation eg send an email, write a report etc.

I now have a need for one delayed_job, as its last step, to lodge another delayed_job.

  • delay.deploy() - when delayed_job runs this, it triggers a deploy action, the last step of which is to ...
  • delay.update_status() - when delayed_job runs this job, it will check the status of the deploy we started. If the deploy is still progressing, we call delay.update_status() again, if the deploy has stopped we write the final deploy status to a db record.
  • Step 1 works fine - after 5 seconds, delayed_job fires up the deploy, which starts the deployment, and then calls delay.update_status().

    But here, instead of update_status() starting up in 5 seconds, delayed_job goes into a busy loop, firing of a bunch of update_status calls, and looping really hard without pause.

    I can see the logs filling up with all these calls, the server slows down, until the end-condition for update_status is reached (deploy has eventually succeeded or failed), and things get quiet again.

    Am I using Delayed_Job::delay() incorrectly, am I missing a basic tenent of this use-case ?


    OK it turns out this is "expected behaviour" - if you are already in the code running for a delayed_job, and you call .delay() again, without specifying a delay, it will run immediately. You need to add the parameter run_at:

      delay(queue: :deploy, run_at: 10.seconds.from_now).check_status
    

    See the discussion in google groups

    链接地址: http://www.djcxy.com/p/65782.html

    上一篇: 延迟与虾和Prawnto的工作

    下一篇: 工作在进入第二项任务时进入繁忙的循环