2012-06-07 16:13:58 +01:00
|
|
|
Capistrano::Configuration.instance(:must_exist).load do
|
|
|
|
|
|
|
|
namespace :resque do
|
|
|
|
task :start do
|
|
|
|
start_workers
|
|
|
|
end
|
|
|
|
|
|
|
|
task :stop do
|
|
|
|
stop_workers
|
|
|
|
end
|
|
|
|
|
|
|
|
task :restart do
|
|
|
|
stop_workers
|
|
|
|
start_workers
|
|
|
|
end
|
|
|
|
|
|
|
|
def rails_env
|
|
|
|
fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_workers
|
2012-06-29 14:09:06 +01:00
|
|
|
# ps = 'ps aux | grep resque | grep -v grep'
|
|
|
|
# run "#{ps} && kill -QUIT `#{ps} | awk '{ print $2 }'` || echo 'Workers already stopped!'"
|
|
|
|
run "cd #{fetch :current_path} && #{rails_env} bundle exec rake resque:stop_workers"
|
2012-06-07 16:13:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def start_workers
|
2012-12-13 17:38:04 +00:00
|
|
|
queue = [
|
2013-01-28 21:59:56 +00:00
|
|
|
:publish_observer,
|
|
|
|
:rpm_worker_observer,
|
|
|
|
:iso_worker_observer,
|
2012-12-13 17:38:04 +00:00
|
|
|
:fork_import,
|
|
|
|
:hook,
|
|
|
|
:clone_build,
|
2014-04-15 19:41:06 +01:00
|
|
|
:middle,
|
2013-01-28 21:59:56 +00:00
|
|
|
:notification
|
2012-12-13 17:38:04 +00:00
|
|
|
].join(',')
|
2014-04-15 19:41:06 +01:00
|
|
|
run "cd #{fetch :current_path} && COUNT=#{workers_count - 1} QUEUE=#{queue} INTERVAL=0.1 #{rails_env} BACKGROUND=yes bundle exec rake resque:workers"
|
|
|
|
run "cd #{fetch :current_path} && COUNT=1 QUEUE=low #{rails_env} BACKGROUND=yes bundle exec rake resque:workers"
|
2012-06-07 16:13:58 +01:00
|
|
|
end
|
2014-02-10 19:36:10 +00:00
|
|
|
|
|
|
|
def remote_file_exists?(full_path)
|
|
|
|
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :scheduler do
|
|
|
|
|
|
|
|
desc "See current scheduler status"
|
|
|
|
task :status do
|
|
|
|
pid = "#{fetch :current_path}/tmp/pids/scheduler.pid"
|
|
|
|
if remote_file_exists?(pid)
|
|
|
|
info capture(:ps, "-f -p $(cat #{pid}) | sed -n 2p")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Starts resque scheduler with default configs"
|
|
|
|
task :start do
|
2014-02-10 19:59:03 +00:00
|
|
|
start_scheduler
|
2014-02-10 19:36:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Stops resque scheduler"
|
|
|
|
task :stop do
|
2014-02-10 19:59:03 +00:00
|
|
|
stop_scheduler
|
|
|
|
end
|
|
|
|
|
|
|
|
task :restart do
|
|
|
|
stop_scheduler
|
|
|
|
start_scheduler
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_scheduler
|
|
|
|
pid = "#{fetch :current_path}/tmp/pids/scheduler.pid"
|
2014-02-26 21:02:48 +00:00
|
|
|
run "cd #{fetch :current_path} && #{rails_env} PIDFILE=#{pid} BACKGROUND=yes VERBOSE=1 MUTE=1 RESQUE_SCHEDULER_INTERVAL=0.5 bundle exec rake resque:scheduler"
|
2014-02-10 19:59:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stop_scheduler
|
2014-02-10 19:36:10 +00:00
|
|
|
pid = "#{fetch :current_path}/tmp/pids/scheduler.pid"
|
|
|
|
if remote_file_exists?(pid)
|
|
|
|
run "cd #{fetch :current_path} && kill -s QUIT $(cat #{pid}); rm #{pid}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-06-07 16:13:58 +01:00
|
|
|
end
|
2014-02-10 19:36:10 +00:00
|
|
|
|
2012-06-07 16:13:58 +01:00
|
|
|
end
|