Sidekiq部署到多个环境

编程入门 行业动态 更新时间:2024-10-07 04:24:02
本文介绍了Sidekiq部署到多个环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

(见下面的详细配置,这是Henley Chiu答案的结果)。

(See below for my detailed config, which is the result of Henley Chiu's answer).

我一直在试图围绕Sidekiq部署包装大脑,我没有真正得到它。我有一个应用程序,具有分段环境和生产环境,在同一台服务器上。我看到的关于sidekiq部署的一切基本上都说只是添加sidekiq / capistrano到你的部署文件,所以我这样做。然后说明是这里是一个带有选项的yml文件,但似乎没有任何解释。我需要命名空间吗?我在初始化文件中看到,但这似乎是指向服务器外部。

I've been trying to wrap my brain around Sidekiq deploys, and I am not really getting it. I have an app with a staging environment, and a production environment, on the same server. Everything I see about sidekiq deploys basically say "just add sidekiq/capistrano to your deploy file", so I did that. And then the instructions are "here's a yml file with options" but nothing seems to be explained. Do I need namespaces? I see that in an initialize file, but that seems to be to point outside the server.

我早些时候部署,每个阶段似乎都是在适当的环境下启动sidekiq ,但是它们都来自相同的队列。我的生产电子邮件正在尝试由舞台sidekiq处理,并且失败。我现在停止了我的舞台,但最终我需要再次使用它。我希望我没有密集,我真的试图理解这一点,只是很难找到一个确定的这里是如何做的。

I deployed earlier, and each stage seems to boot sidekiq up with the proper environment, but they both process from the same queues. My emails from production were trying to be processed by the stage sidekiq, and failing. I stopped my stage for now, but eventually I will need to use it again. I hope I'm not being dense, I've really tried to understand this and am just having a hard time with finding a definitive "here's how it's done".

对于什么是值得的,这里是config / sidekiq.yml(在部署期间加载正常):

For what it's worth, here is config/sidekiq.yml (which is loaded fine during the deploy):

:concurrency: 5 :verbose: false :pidfile: ./tmp/pids/sidekiq.pid :logfile: ./log/sidekiq.log :queues: - [carrierwave, 7] - [client_emails, 5] - [default, 3] staging: :concurrency: 10 production: :concurrency: 25

日志文件和pids似乎在正确的位置,但队列只是合并。任何帮助将是巨大的!

Log files, and pids seem to be in the right spot, but the queues are just merged. Any help would be GREAT!

另外,如果重要:

Rails 3.2.11, passenger, nginx, rvm, Ubuntu 12.10, and Ruby 1.9.3

详细配置(答案):

首先,我在端口7777(或除了默认6379之外的任何端口)上设置了一个新的redis服务器。几乎遵循了我第一次使用的 redis快速入门指南。

然后我做了initizers文件;这有客户端和服务器配置。两者都需要使sidekiq工作多级。

Then I made the initilizer file; this has both the client and the server config. Both are required to make sidekiq work multistage.

请注意,我正在使用外部YAML文件进行设置。我正在使用 SettingsLogic 来使事情变得更简单,但您也可以轻松地通过包含文件来做这个。通过使用yaml文件,我们不必接触我们的环境/分段或生产文件。

Note that I am using an external YAML file for the settings. I am using SettingsLogic for this to make things easier, but you can just as easily do this yourself by including the file. By using a yaml file, we don't have to touch our environments/staging or production files.

# config/initializers/sidekiq.rb server = Settings.redis.server port = Settings.redis.port db_num = Settings.redis.db_num namespace = Settings.redis.namespace Sidekiq.configure_server do |config| config.redis = { url: "redis://#{server}:#{port}/#{db_num}", namespace: namespace } end

我在使用乘客 - sidekiq wiki的疑难解答页面建议在使用独角兽或乘客时对设置进行更改,因此我在其中添加了代码,用于客户端设置:

I am using passenger - the troubleshooting page of the sidekiq wiki recommends a change for the setup when using unicorn or passenger, so I added the code there for the client setup:

# config/initializers/sidekiq.rb (still) if defined?(PhusionPassenger) PhusionPassenger.on_event(:starting_worker_process) do |forked| Sidekiq.configure_client do |config| config.redis = { url: "redis://#{server}:#{port}/#{db_num}", namespace: namespace } end if forked end end

这是我的设置文件(显然值更改):

This is my Settings file (obviously values changed):

#config/settings.yml defaults: &defaults redis: &redis_defaults server: 'localhost' port: 6379 db_num: 0 namespace: 'sidekiq_development' development: <<: *defaults test: <<: *defaults staging: <<: *defaults redis: <<: *redis_defaults port: 8888 namespace: 'sidekiq_staging' production: <<: *defaults redis: <<: *redis_defaults port: 7777 namespace: 'sidekiq_production'

我发现将命名空间添加到config / sidekiq.yml文件似乎不起作用 - sideki q将使用正确的端口在部署时启动,但实际上不会处理任何内容。但是,由于wiki建议使用命名空间,所以我最终只是将其添加到init文件中。

I found that adding the namespace to the config/sidekiq.yml file didn't seem to work - sidekiq would boot on deploy using the right port, but wouldn't actually process anything. But since the wiki recommends using a namespace, I ended up just adding it to the init file.

我希望对他人有帮助,因为我真的很难明白,以前没有做过很多这样的设置。

I hope this helpful for others, because this was really hard for me to understand, having not done a lot of this kind of setup before.

推荐答案

在你的initializers / sidekiq.rb文件中,你指定Redis将所有环境都启动。 对我来说,它是:

In your initializers/sidekiq.rb file, you specify the Redis queue all environments boot up with. For mine it is:

redisServer = "localhost" Sidekiq.configure_server do |config| config.redis = { :url => 'redis://' + redisServer + ':6379/0' } end

如果您希望每个环境从单独的队列进行处理,您可以在每个环境的环境文件夹中具有特定的sidekiq.rb文件。每个都有不同的redis服务器。

If you want each environment to process from separate queues, you can have specific sidekiq.rb files in the environments folder for each environment. Each with different redis servers.

更多推荐

Sidekiq部署到多个环境

本文发布于:2023-11-28 03:34:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640798.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   环境   Sidekiq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!