如何从Capistrano开始1名生产Resque工作人员?

时间:2011-09-11 17:57:54

标签: ruby-on-rails ruby-on-rails-3 capistrano background-process resque

我已经安装了Redis / Resque,但是当我部署时,我很难从Capistrano开始/重新启动它。

我的需求相当简单:我只有1个队列,只需要1个工人,而且我不使用monit或god。

基于this blog post,我的deploy.rb包含:

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end

  task :restart_resque do 
    pid_file = "#{shared_path}/pids/resque.pid" 
    run "test -f #{pid_file} && cd #{current_path} && kill -s QUIT `cat #{pid_file}` || rm -f #{pid_file}"
    run "cd #{current_path}; RAILS_ENV=production QUEUE='*' VERBOSE=1 nohup rake environment resque:work& > #{shared_path}/log/resque.log && echo $! > #{pid_file}"
  end

end

after 'deploy:restart', 'deploy:restart_resque'

我的resque.rake文件(基于Railscast)有:

require "resque/tasks"  

task "resque:setup" => :environment

当我cap deploy时,一切似乎都有效,但当我查看resque-web时,没有工人在运行......

1 个答案:

答案 0 :(得分:2)

我建议您查看此StackOverflow questionthis gist以获取相当多的建议。