-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathRakefile
47 lines (41 loc) · 1.29 KB
/
Rakefile
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
#!/usr/bin/env rake
require 'resque/tasks'
task "resque:setup" => :environment
# Start a worker with proper env vars and output redirection
def run_worker(queue = "*", count = 1)
puts "Starting #{count} worker(s) with QUEUE: #{queue}"
ops = {:pgroup => true,
:err => [("#{File.dirname(__FILE__)}/log/resque_err").to_s, "a"],
:out => [("#{File.dirname(__FILE__)}/log/resque_stdout").to_s, "a"]
}
env_vars = {"QUEUE" => queue.to_s}
count.times {
## Using Kernel.spawn and Process.detach because regular system() call would
## cause the processes to quit when capistrano finishes
pid = spawn(env_vars, "bundle exec rake resque:work", ops)
Process.detach(pid)
}
end
namespace :resque do
task :setup => :environment
desc "Restart running workers"
task :restart => :environment do
Rake::Task['resque:stop'].invoke
Rake::Task['resque:start'].invoke
end
desc "Quit running workers"
task :stop => :environment do
pids = Resque.workers.map { |w| w.worker_pids }.flatten.uniq
if pids.empty?
puts "No workers to kill"
else
syscmd = "kill -s QUIT #{pids.join(' ')}"
puts "Running syscmd: #{syscmd}"
system(syscmd)
end
end
desc "Start workers"
task :start => [:environment, "resque:setup"] do
run_worker("*", 4)
end
end