Search code examples
ruby-on-railsdelayed-job

How do I stop delayed_job if I'm running it with the -m "monitor" option?


How do I stop delayed_job if I'm running it with the -m "monitor" option? The processes keep getting restarted!

The command I start delayed_job with is:

script/delayed_job -n 4 -m start

The -m runs a monitor processes that spawns a new delayed_job process if one dies.

The command I'm using to stop is:

script/delayed_job stop

But that doesn't stop the monitor processes, which in turn start up all the processes again. I would just like them to go away. I can kill them, which I have, but I was hoping there was some command line option to just shut the whole thing down.


Solution

  • In my capistrano deploy script I have this:

    desc "Start workers"
    task :start_workers do
      run "cd #{release_path} && RAILS_ENV=production script/delayed_job -m -n 2 start"
    end
    
    desc "Stop workers"
    task :stop_workers do
      run "ps xu | grep delayed_job | grep monitor | grep -v grep | awk '{print $2}' | xargs -r kill"
      run "cd #{current_path} && RAILS_ENV=production script/delayed_job stop"
    end
    

    To avoid any errors that may stop your deployment script:

    • "ps xu" only show processes owned by the current user
    • "xargs -r kill" only invoke the kill command when there is something to kill

    I only kill the delayed_job monitor, and stop the delayed_job deamon the normal way.