Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to gracefully restart delayed_job consumers?
    primarykey
    data
    text
    <p>I'm wondering what's the best way to gracefully restart delayed_job consumers after a new code push? I'm pushing code with capistrano and I know there are commands to restart, but if there are jobs currently running, the command either hangs (and my deploy takes forever) or it forcefully quits the currently running job and I lose data.</p> <p>Ideally I'd like my deploy to happen like this:</p> <ol> <li>Existing delayed_job consumer is running with version 1 code</li> <li>I run <code>cap deploy</code> and version 2 code is pushed out to new servers</li> <li>During the deploy, we touch a file to tell the delayed_job to restart when it's done processing the current job. This can be done a bunch of different ways, but I was thinking it would be similar to how passenger is gracefully restarted</li> <li>Existing delayed_job consumer continues to finish the current job with version 1 code</li> <li>Current job finishes, delayed_job consumer sees that it needs to restart itself before continuing to process jobs</li> <li>delayed_job consumer automatically restarts, now running version 2 code</li> <li>delayed_job consumer continues to process jobs, now running on version 2 code</li> </ol> <p>I've tried to insert some code to restart before a job runs by checking the current revision of the code but every time I do that, it just dies and doesn't actually restart anything. Sample code below:</p> <pre><code>def before(job) # check to make sure that the version of code here is the right version of code live_git_hash = LIVE_REVISION local_git_hash = LOCAL_REVISION if live_git_hash != local_git_hash # get environment to reload in environment = Rails.env # production, development, staging # restart the delayed job system %x("export RAILS_ENV=#{environment} &amp;&amp; ./script/delayed_job restart") end end </code></pre> <p>It detects it just fine but it dies on the shell call. Any ideas?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload