简体   繁体   English

Rails:在没有新贵脚本的情况下管理多个sidekiqs

[英]Rails: managing multiple sidekiqs without upstart script

Once upon a time, I had one app - Cashyy . 从前,我有一个应用程序Cashyy It used sidekiq. 它使用了sidekiq。 I deployed it and used this upstart script to manage sidekiq (start/restart). 我部署了它,并使用此新贵脚本来管理sidekiq(启动/重新启动)。

I decide to deploy another app to the same server. 我决定将另一个应用程序部署到同一服务器上。 The app (let's call it Giimee ) also uses sidekiq. 该应用程序(我们称其为Giimee )也使用sidekiq。

And here is the issue. 这是问题所在。 Sometimes I need to restart sidekiq for Cashyy , but not for Giimee . 有时候,我需要为Cashyy重新启动sidekiq,而不是为Giimee重新启动。 Now, as I understand I will need to hack something using index thing (in upstart script and managing sidekiqs: sudo restart sidekiq index=1 ) (if I understood it correctly). 现在,据我了解,我将需要使用index事物(在upstart脚本和管理sidekiqs: sudo restart sidekiq index=1 )中进行黑客入侵(如果我正确理解的话)。

BUT! 但!

I have zero desire to dabble with these indexes (nightmare to support? Like you need to know how many apps are using sidekiq and be sure to assign unique index to each sidekiq. And to know assigned index if you want to restart specific sidekiq). 我对使用这些索引不屑一顾(需要噩梦般的支持?就像您需要知道有多少应用程序正在使用sidekiq,并确保为每个sidekiq分配唯一索引。如果要重新启动特定的sidekiq,则要知道分配的索引)。

So here is the question: how can I isolate each sidekiq (so I would not need to maintain the index ) and still get the stability and usability of upstart (starting the process, restarting, etc.)? 所以这是一个问题:如何隔离每个sidekiq(这样我就不需要维护index ),仍然可以获得新贵的稳定性和可用性(启动进程,重新启动等)?

Or maybe I don't understand something and the thing with index is state of art? 或者,也许我听不懂某些东西,而带有index的东西却是最先进的?

As an alternative to an upstart script, you can use Capistrano and Capistrano-Sidekiq to manage those Sidekiqs. 作为新贵脚本的替代方法,您可以使用CapistranoCapistrano-Sidekiq管理那些Sidekiq。

We have Sidekiq running on 3 machines and have had a good experience with these two libraries/tools. 我们的Sidekiq在3台计算机上运行,​​并且对这两个库/工具都有很好的经验。

Note : we currently use an older version of Capistrano (2.15.5) 注意 :我们目前使用的是Capistrano的旧版本(2.15.5)

In our architecture, the three machines are customized slightly on deploy. 在我们的体系结构中,这三台机器在部署时进行了少量定制。 This led us to break up our capistrano deploy scripts by machine so that we could customize some classes, manage Sidekiq, etc. Our capistrano files are structured something like this: 这导致我们按机器分解了capistrano部署脚本,以便我们可以自定义一些类,管理Sidekiq等。我们的capistrano文件的结构如下:

- config/
  - deploy.rb
  - deploy/ 
    - gandalf.rb
    - gollum.rb
    - legolas.rb

With capistrano-sidekiq, we are able to control, well, Sidekiq :) at any time (during a deploy or otherwise). 使用capistrano-sidekiq,我们可以随时(在部署期间或其他期间)控制Sidekiq :)。 We set up the Sidekiq aspects of our deploy scripts in the following way: 我们通过以下方式设置部署脚本的Sidekiq方面:

# config/deploy.rb
# global sidekiq settings
set :sidekiq_default_hooks, false
set :sidekiq_cmd, "#{fetch(:bundle_cmd, 'bundle')} exec sidekiq"
set :sidekiqctl_cmd, "#{fetch(:bundle_cmd, 'bundle')} exec sidekiqctl"    
set :sidekiq_role, :app
set :sidekiq_pid, "#{current_path}/tmp/pids/sidekiq.pid"
set :sidekiq_env,  fetch(:rack_env, fetch(:rails_env, fetch(:default_stage)))
set :sidekiq_log,  File.join(shared_path, 'log', 'sidekiq.log')

# config/deploy/gandalf.rb 
# Custom Sidekiq settings 
set :sidekiq_timeout, 30
set :sidekiq_processes, 1
namespace :sidekiq do
  # .. code omitted from methods and tasks for brevity
  def for_each_process(&block)   
  end

  desc 'Quiet sidekiq (stop accepting new work)'
  task :quiet, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
  end

  desc 'Stop sidekiq'
  task :stop, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
  end

  desc 'Start sidekiq'
  task :start, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
  end

  desc 'Restart sidekiq'
  task :restart, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
  end    
end

When I need to restart one of my Sidekiq instances, I can just go to my terminal and execute the following: 当我需要重启我的Sidekiq实例之一时,我可以转到终端并执行以下操作:

$ bundle exec cap gandalf sidekiq:restart
$ bundle exec cap gollum sidekiq:stop 

It's made Sidekiq management quite painless for our team and thought it would be worth sharing in the event something similar could help you out. 这使Sidekiq的管理人员对我们的团队非常轻松,并认为有必要分享类似的东西来为您提供帮助。

You create two services: 您创建两个服务:

cp sidekiq.conf /etc/init/cashyy.conf
cp sidekiq.conf /etc/init/glimee.conf

Edit each as necessary. 根据需要进行编辑。 sudo start cashyy , sudo stop glimee , etc. Now you'll have two completely separate Sidekiq processes running. sudo start cashyysudo stop glimee等。现在,您将运行两个完全独立的Sidekiq进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM