Created
April 8, 2014 03:20
-
-
Save jnarowski/10086882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remote_process_exists?(pid_file) | |
capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2 | |
end | |
namespace :resques do | |
desc "Start Resque workerss" | |
task :start do | |
puts "Starting #{resque_num_of_queues} worker(s) with QUEUE: #{resque_queue_name}" | |
resque_num_of_queues.times do |i| | |
pid = "#{current_path}/tmp/pids/resque_worker_#{i}.pid" | |
run "cd #{current_path} && nohup #{rake_cmd} environment resque:work \ | |
RAILS_ENV=#{rails_env} QUEUE=#{resque_queue_name} \ | |
INTERVAL=#{resque_polling_interval} PIDFILE=#{pid} BACKGROUND=yes \ | |
VVERBOSE=#{resque_verbosity} \ | |
& >> #{current_path}/log/resque-worker#{i}.log 2>&1" | |
end | |
end | |
desc "Quit running Resque workerss" | |
task :stop do | |
resque_num_of_queues.times do |i| | |
pid = "#{current_path}/tmp/pids/resque_worker_#{i}.pid" | |
if remote_file_exists?(pid) | |
if remote_process_exists?(pid) | |
logger.important("Stopping...", "Resque Worker #{i}") | |
run "#{try_sudo} kill `cat #{pid}`" | |
else | |
run "rm #{pid}" | |
logger.important("Resque Worker #{i} is not running.", "Resque") | |
end | |
else | |
logger.important("No PIDs found. Check if Resque is running.", "Resque") | |
end | |
end | |
end | |
desc "Restart Resque" | |
task :restart do | |
stop | |
start | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment