Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.