Stop resque workers through rake. Refs #543

This commit is contained in:
Pavel Chipiga 2012-06-29 16:09:06 +03:00
parent 5f296a87a4
commit d3e89393a8
2 changed files with 16 additions and 3 deletions

View File

@ -20,12 +20,15 @@ Capistrano::Configuration.instance(:must_exist).load do
end
def stop_workers
ps = 'ps aux | grep resque | grep -v grep'
run "#{ps} && kill -QUIT `#{ps} | awk '{ print $2 }'` || echo 'Workers already stopped!'"
# ps = 'ps aux | grep resque | grep -v grep'
# run "#{ps} && kill -QUIT `#{ps} | awk '{ print $2 }'` || echo 'Workers already stopped!'"
# run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'`"
# run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1 &"
run "cd #{fetch :current_path} && #{rails_env} bundle exec rake resque:stop_workers"
end
def start_workers
run "cd #{fetch :current_path} && COUNT=#{ workers_count } QUEUE=fork_import,hook,clone_build,notification #{ rails_env } BACKGROUND=yes bundle exec rake resque:workers"
run "cd #{fetch :current_path} && COUNT=#{workers_count} QUEUE=fork_import,hook,clone_build,notification #{rails_env} BACKGROUND=yes bundle exec rake resque:workers"
end
end
end

10
lib/tasks/resque.rake Normal file
View File

@ -0,0 +1,10 @@
namespace :resque do
desc 'Stop all Resque workers'
task :stop_workers => :environment do
pids = []
Resque.workers.each do |worker|
pids << worker.to_s.split(/:/).second
end
system("kill -QUIT #{pids.join(' ')}") if pids.size > 0
end
end