Tuesday, 10 July 2012

DJ demons

On production, you would want the worker to be running all the time. Also, it will be nice to have the ability to stop the worker just before the deployment and start it again once the deployment finishes. It sounds complicated, but its pretty easy to set up.
First, install the daemons gem:

# Add in environment.rb
 config.gem 'daemons'

$ rake gems:install

Then, copy this script in your rails project in file script/delayed_job and give it execute permission. This creates a worker daemon, which when started keeps running as a background process.
Alternately, instead of daemons gem, you can use daemon-spawn gem.
Install the gem on the host where you want the delayed_job daemon to run:

$ sudo gem sources -a http://gems.github.com
$ sudo gem install alexvollmer-daemon-spawn

And then copy this script instead in script/delayed_job. Rest all of the following steps are identical, whichever gem and script/delayed_job you choose.

# start the worker daemon
$ ruby script/delayed_job start

# stop it
$ ruby script/delayed_job stop


No comments:

Post a Comment