ruby-on-rails – 通过Capistrano任务启动具有特定队列的多个DelayedJob工作

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 通过Capistrano任务启动具有特定队列的多个DelayedJob工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在研究使用具有delayed_job的队列.我找到了 this page,其中列出了各种启动工作的方式,但是我想保留我当前的Capistrano方法
set :delayed_job_args,"-n 2 -p ecv2.production"
after "deploy:start","delayed_job:start"
...

我想知道如何修改delayed_job_args来处理具有特定队列的1个worker,每个其他作业有1个worker.到目前为止,我所有的都是如此覆盖每个任务:

namespace :delayed_job do
  task :restart,:roles => :app do
    run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job -p ecv2.production --queue=export restart"
    run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job -p ecv2.production restart"
  end
end

…但是没有乐趣有什么建议么?

解决方法

我将我的作业分成两个队列,一个工作者在我的deploy.rb文件中使用此设置隔离到每个队列:
namespace :delayed_job do
  task :start,roles: :app do
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i queue_one --queue=one start"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i queue_two --queue=two start"
  end

  task :stop,roles: :app do
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i queue_one --queue=one stop"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i queue_two --queue=two stop"
  end

  task :restart,roles: :app do
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i queue_one --queue=one restart"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i queue_two --queue=two restart"
  end
end

命令的-i名称部分非常重要.这是允许多个delayed_job实例运行的部分.

如果要将工作人员添加到特定的队列中,那么您可以像这样扩展它们(我仅有两名工作人员在排队队列中排队,另外一名员工排在队列二上):

namespace :delayed_job do
  task :start,roles: :app do
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i one1 --queue=one start"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i one2 --queue=one start"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i two --queue=two start"
  end

  task :stop,roles: :app do
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i one1 stop"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i one2 stop"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i two stop"
  end

  task :restart,roles: :app do
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i one1 --queue=one restart"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i one2 --queue=one restart"
    run "cd #{current_path}; #{rails_env} bundle exec script/delayed_job -i two --queue=two restart"
  end
end
原文链接:https://www.f2er.com/ruby/271453.html

猜你在找的Ruby相关文章