2023-05-12 13:01:12 +02:00
|
|
|
require 'resque/tasks'
|
2012-12-23 17:38:04 +01:00
|
|
|
|
2012-12-30 14:47:02 +01:00
|
|
|
def run_worker(queue, count = 1)
|
|
|
|
puts "Starting #{count} worker(s) with QUEUE: #{queue}"
|
2023-05-12 13:01:12 +02:00
|
|
|
ops = { pgroup: true, err: ['log/resque_worker_foodsoft_notifier.log', 'a'],
|
|
|
|
out: ['log/resque_worker_foodsoft_notifier.log', 'a'] }
|
|
|
|
env_vars = { 'QUEUE' => queue.to_s, 'PIDFILE' => 'tmp/pids/resque_worker_foodsoft_notifier.pid' }
|
|
|
|
count.times do
|
2012-12-30 14:47:02 +01:00
|
|
|
## Using Kernel.spawn and Process.detach because regular system() call would
|
|
|
|
## cause the processes to quit when capistrano finishes
|
2023-05-12 13:01:12 +02:00
|
|
|
pid = spawn(env_vars, 'bundle exec rake resque:work', ops)
|
2012-12-30 14:47:02 +01:00
|
|
|
Process.detach(pid)
|
2023-05-12 13:01:12 +02:00
|
|
|
end
|
2012-12-30 14:47:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
namespace :resque do
|
2023-05-12 13:01:12 +02:00
|
|
|
task setup: :environment
|
2012-12-30 14:47:02 +01:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Restart running workers'
|
2012-12-30 14:47:02 +01:00
|
|
|
task :restart_workers do
|
|
|
|
Rake::Task['resque:stop_workers'].invoke
|
|
|
|
Rake::Task['resque:start_workers'].invoke
|
|
|
|
end
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Quit running workers'
|
2012-12-30 14:47:02 +01:00
|
|
|
task :stop_workers do
|
|
|
|
pids = File.read('tmp/pids/resque_worker_foodsoft_notifier.pid').split("\n")
|
|
|
|
if pids.empty?
|
2023-05-12 13:01:12 +02:00
|
|
|
puts 'No workers to kill'
|
2012-12-30 14:47:02 +01:00
|
|
|
else
|
|
|
|
syscmd = "kill -s QUIT #{pids.join(' ')}"
|
|
|
|
puts "Running syscmd: #{syscmd}"
|
|
|
|
system(syscmd)
|
|
|
|
end
|
|
|
|
end
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Start workers'
|
2012-12-30 14:47:02 +01:00
|
|
|
task :start_workers do
|
2023-05-12 13:01:12 +02:00
|
|
|
run_worker('foodsoft_notifier')
|
2012-12-30 14:47:02 +01:00
|
|
|
end
|
|
|
|
end
|