[refs #510] Add resque recipes for capistrano

This commit is contained in:
konstantin.grabar 2012-06-01 16:54:58 +04:00
parent 216b0da98e
commit 7d58937149
2 changed files with 43 additions and 0 deletions

View File

@ -37,6 +37,7 @@ require './lib/recipes/nginx'
require './lib/recipes/unicorn' require './lib/recipes/unicorn'
require './lib/recipes/bluepill' require './lib/recipes/bluepill'
require './lib/recipes/delayed_job' require './lib/recipes/delayed_job'
require './lib/recipes/resque'
namespace :deploy do namespace :deploy do
task :stub_xml_rpc do task :stub_xml_rpc do
@ -89,6 +90,11 @@ after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start" after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart" after "deploy:restart", "delayed_job:restart"
# Resque
after "deploy:stop", "resque:stop"
after "deploy:start", "resque:start"
after "deploy:restart", "resque:restart"
after "deploy:restart", "deploy:cleanup" after "deploy:restart", "deploy:cleanup"
namespace :rake_tasks do namespace :rake_tasks do

37
lib/recipes/resque.rb Normal file
View File

@ -0,0 +1,37 @@
# -*- encoding : utf-8 -*-
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 start_workers
pids = Array.new
Resque.workers.each do |worker|
pids << worker.to_s.split(/:/).second
end
if pids.size > 0
system("kill -QUIT #{pids.join(' ')}")
end
end
def stop_workers
run "cd #{fetch :release_path} && QUEUE=* bundle exec rake resque:work"
end
end
end