public
Last active

  • Download Gist
resque.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
require 'resque/tasks'
 
task "resque:setup" => :environment
 
namespace :queue do
task :start => :environment do
pidfile = Rails.root.join('tmp', 'pids', 'resque.pid')
logfile = Rails.root.join('log', 'resque.log')
errlogfile = Rails.root.join('log', 'resque_errors.log')
 
pid = fork do
$stdout = File.new(logfile, 'w')
$stdin = File.new(errlogfile, 'w')
 
worker = Resque::Worker.new('*')
worker.work(ENV['INTERVAL'] || 5)
end
 
if pid
File.open(pidfile, 'w') do |f|
f.write(pid)
f.close
end
puts "Resque successfully started with pid: #{pid}"
end
end
 
task :stop => :environment do
require "timeout"
 
pidfile = Rails.root.join('tmp', 'pids', 'resque.pid')
if File.exists?(pidfile)
pid = File.read(pidfile).to_i
Process.kill(15, pid)
begin
Timeout::timeout(15) do
Process.waitpid(pid)
end
rescue Timeout::Error
Process.kill(9, pid)
rescue => e
puts e.to_s
end
else
puts "error: Pidfile does not exists"
end
File.delete(pidfile) if File.exists?(pidfile)
end
 
task :restart => :environment do
Rake::Task["queue:stop"].invoke
Rake::Task["queue:start"].invoke
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.