-
-
Save e1senh0rn/913503 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
namespace :resque do | |
task :setup => :environment do | |
# generic worker setup, e.g. Hoptoad for failed jobs | |
end | |
# QUIT - Wait for child to finish processing then exit | |
# TERM / INT - Immediately kill child then exit | |
# USR1 - Immediately kill child but don't exit | |
# USR2 - Don't start to process any new jobs | |
# CONT - Start to process new jobs again after a USR2 | |
desc 'Stop Resque workers' | |
task :stop => :setup do | |
pids = Array.new | |
Resque.workers.each do |worker| | |
pids << worker.to_s.split(/:/).second | |
end | |
signal = ENV['SIGNAL'] || 'QUIT' | |
if pids.size > 0 | |
system("kill -#{signal} #{pids.join(' ')}") | |
end | |
end | |
desc 'Start Resque workers' | |
task :start => :setup do | |
RESQUE_WORKERS.each do |queue, count| | |
args = [] | |
args << "RAILS_ENV=#{Rails.env}" | |
args << "COUNT=#{count}" | |
args << "QUEUE=#{queue}" | |
args << "VERBOSE=1" | |
args << "PIDFILE=tmp/pids/resque_worker_#{queue}.pid" | |
log = "log/resque_worker_#{queue}.log" | |
system("nohup rake resque:workers #{args.join(' ')} &>#{log} &") | |
end | |
end | |
task :restart => :environment do | |
Rake::Task["resque:stop"].invoke | |
Rake::Task["resque:start"].invoke | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment