rosa-build/lib/recipes/resque.rb

86 lines
2.1 KiB
Ruby
Raw Normal View History

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
# 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"
end
def start_workers
queue = [
2013-01-28 21:59:56 +00:00
:publish_observer,
:rpm_worker_observer,
:iso_worker_observer,
:fork_import,
:hook,
:clone_build,
2013-01-28 21:59:56 +00:00
:notification
].join(',')
run "cd #{fetch :current_path} && COUNT=#{workers_count} QUEUE=#{queue} #{rails_env} BACKGROUND=yes bundle exec rake resque:workers"
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
end
2014-02-10 19:36:10 +00:00
end