Skip to content

Instantly share code, notes, and snippets.

@MBO
Created September 7, 2010 10:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MBO/568143 to your computer and use it in GitHub Desktop.
Save MBO/568143 to your computer and use it in GitHub Desktop.
namespace :delayed_job do
desc "*HACK* Restart the delayed_job process"
task :restart do
stop
enforce_stop_delayed_job
start
end
# Send SIGTERM to delayed_job associated with current logfile and then
# wait for every delayed_job to finish
def enforce_stop_delayed_job
run %Q{
lsof '#{current_path}/log/delayed_job.log' | awk '/^ruby/ { system("kill " $2) }' ;
COUNT=1;
until [ $COUNT -eq 0 ]; do
COUNT=`lsof '#{current_path}/log/delayed_job.log' | grep '^ruby' |wc -l` ;
echo 'waiting for delayed_job to end' ;
sleep 2 ;
done
}.split("\n").join('')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment