From 7d5893714938e42c18d3f4c0de39ed33638ba0b0 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 1 Jun 2012 16:54:58 +0400 Subject: [PATCH] [refs #510] Add resque recipes for capistrano --- config/deploy.rb | 6 ++++++ lib/recipes/resque.rb | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/recipes/resque.rb diff --git a/config/deploy.rb b/config/deploy.rb index ac5e272f1..0c69a6379 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -37,6 +37,7 @@ require './lib/recipes/nginx' require './lib/recipes/unicorn' require './lib/recipes/bluepill' require './lib/recipes/delayed_job' +require './lib/recipes/resque' namespace :deploy do task :stub_xml_rpc do @@ -89,6 +90,11 @@ after "deploy:stop", "delayed_job:stop" after "deploy:start", "delayed_job:start" 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" namespace :rake_tasks do diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb new file mode 100644 index 000000000..c66623d96 --- /dev/null +++ b/lib/recipes/resque.rb @@ -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