views:

1452

answers:

2

I'm using delayed_job with capistrano and would like a way to start delayed_job on startup of the web application using the 'script/delayed_job start'. This way capistrano can restart it on deploy. If the server gets rebooted then my delayed_jobs should start up with the project.

How can I do this? Should I be looking at doing this in the environment files or as an initializer?

+2  A: 

You should create one recipe with the restart command.

namespace :delayed_job do 
    desc "Restart the delayed_job process"
    task :restart, :roles => :app do
        run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job restart"
    end
end

Then you add it to be executed at the end of your deployment.

after "deploy:update_code", "delayed_job:restart"
Damien MATHIEU
I've already got this recipe in my capistrano and it's working. My question was more related to rebooting the server. Currently I've done a work around where on boot I just run a script in my init.d and start the delayed_job daemon. It would be nice to have that as part of my application though.
map7
You could use [god](http://god.rubyforge.org/) to manage the process and boot it automatically when the machine boots.
Damien MATHIEU
delayed_job has its own recipes.rb file that has the above task pretty much exactly, plus delayed_job:start and delayed_job:stop tasks.
Ryan McCuaig
Hi @Ryan: i noticed this too, but i am stuck as to how to include/require those inside my `deploy.rb`. Just `require `delayed_job'` does not work for me (i am using the version from git).
nathanvda
A: 

It's possible to boot & monitor delayed_job with monit:
http://stackoverflow.com/questions/1226302/how-to-monitor-delayed-job-with-monit

Laurynas