Skip to content

Instantly share code, notes, and snippets.

@e1senh0rn
Forked from Ptico/resque.rb
Created April 11, 2011 13:18
Show Gist options
  • Save e1senh0rn/913503 to your computer and use it in GitHub Desktop.
Save e1senh0rn/913503 to your computer and use it in GitHub Desktop.
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