Skip to content

Instantly share code, notes, and snippets.

@btelles
Forked from jimeh/delayed_job.rb
Created May 4, 2010 18:58
Show Gist options
  • Save btelles/389809 to your computer and use it in GitHub Desktop.
Save btelles/389809 to your computer and use it in GitHub Desktop.
#
# NOTICE: The stop/restart tasks won't work properly due to a bug in the daemons gem
# unless you use the ghazel-daemons gem by putting this in your environment.rb file:
#
# config.gem "ghazel-daemons", :lib => "daemons"
# gem "ghazel-daemons"
# require "daemons"
#
# This will force-load the 'ghazel-daemons' gem and make sure it's used instead of
# the 'daemons' gem. It works even with the 'daemons' gem installed, so you won't
# have any dependency issues with gems that specifically depend upon daemons.
after "deploy:start", "dj:start"
after "deploy:stop", "dj:stop"
before "deploy:update_code", "dj:stop"
after "deploy:restart", "dj:restart"
# delayed_job
namespace :dj do
desc "Start delayed_job daemon."
task :start, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job start"
end
desc "Stop delayed_job daemon."
task :stop, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job stop"
end
desc "Restart delayed_job daemon."
task :restart, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job restart"
end
desc "Show delayed_job daemon status."
task :status, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job status"
end
desc "List the PIDs of all running delayed_job daemons."
task :pids, :roles => :app do
run "lsof | grep '#{deploy_to}/shared/log/delayed_job.log' | cut -c 1-21 | uniq | awk '/^ruby/ {if(NR > 0){system(\"echo \" $2)}}'"
end
desc "Force kill all running delayed_job daemons."
task :kill, :roles => :app do
run "lsof | grep '#{deploy_to}/shared/log/delayed_job.log' | cut -c 1-21 | uniq | awk '/^ruby/ {if(NR > 0){system(\"kill -9 \" $2)}}'"
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job stop" # removes orphaned pid file(s)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment