多环境的 Sidekiq 配置 [英] Sidekiq configuration for multiple environments

查看:38
本文介绍了多环境的 Sidekiq 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了多个来源并尝试了各种方案,但无法解决此问题,因此出现了问题.请为我指明正确的方向.

I have looked at multiple sources and tried various scenarios but couldn't resolve this hence the issue. Please point me in the right direction.

和大家一样,我有 3 个 env(开发、暂存和生产).

Like everybody I have 3 env (development, staging and production).

我的 sidekiq.yml 文件中有以下内容

I have the following in my sidekiq.yml file

# Options here can still be overridden by cmd line args.
#   sidekiq -C config.yml  
---
:verbose: false
:namespace: xyz
:logfile: log/sidekiq.log
:concurrency:  25
:strict: false
:pidfile: tmp/pids/sidekiq.pid
:queues:
  - [stg_xyz_tests_queue, 10]
  - [stg_default_xyz_queue, 2]
  - [stg_xyz_default_queue, 3]
development:
  :verbose: true
  :concurrency:  15
  :queues:
    - [dev_xyz_queue, 10]
    - [dev_default_xyz_queue, 2]
    - [dev_xyz_default_queue, 3]
staging:
  :queues:
    - [stg_xyz_queue, 10]
    - [stg_default_xyz_queue, 2]
    - [stg_xyz_default_queue, 3]
production:
  :queues:
    - [prod_xyz_queue, 10]
    - [prod_default_xyz_queue, 2]
    - [prod_xyz_default_queue, 3]

有了这个,我希望当我用命令启动 sidekiq

With this I was hoping that when I start sidekiq with the command

RAILS_ENV=#{rails_env} bundle exec sidekiq -C config/sidekiq.yml

它会从配置文件中获取所有值并使用适当的队列和日志文件启动 sidekiq,但它不起作用.Sidekiq 启动但它只创建 stg_xyz_tests_queue、stg_default_xyz_queue 和 stg_xyz_default_queue,无论我们使用什么环境.

that it would pickup all the values from the configuration file and start sidekiq with the appropriate queues and log file at log/sidekiq.log but that doesn't work. Sidekiq starts but it only creates the stg_xyz_tests_queue, stg_default_xyz_queue and stg_xyz_default_queue no matter what environment we use.

我尝试的另一种方法是在 config/environments/development.rb 中使用以下代码

The other approach I tried was using the following code in the config/environments/development.rb

  #configure Sidekiq for dev environment
  Sidekiq.configure_server do |config|
    config.options[:namespace] = "xyz"
    config.options[:concurrency] = 25
    config.options[:verbose] = true
    config.options[:strict] = false
    config.options[:logfile] = "log/sidekiq.log"
    config.options[:pidfile] = "tmp/pids/sidekiq.pid"

    queues = Array.new
    10.times do
      queues.push "dev_xyz_queue"
    end

    2.times do
      queues.push "dev_default_xyz_queue"
    end

    3.times do
      queues.push "dev_xyz_default_queue"
    end

    config.options[:queues] = queues
    puts "Sidekiq server config options for development => #{config.options.to_yaml}"
  end

这样就可以正常创建队列,但未创建或写入日志文件,我需要为所有 3 个环境复制此代码.

With this the queues are created ok but the logfile is not created or written and I need to duplicate this code for all the 3 environments.

让 sidekiq 在我的设置中无缝工作的最佳方法是什么提前感谢您的帮助!!!

What is the best way to get sidekiq working seamlessly for my setup Thanks for your help in advance !!!

推荐答案

使用 -e 选项

bundle exec sidekiq -e beta -C config/sidekiq.yml

如果所有环境(开发、暂存和生产)都在同一台服务器上,则使用命名空间.在您的 initializers/sidekiq.rb 文件中,

If all environments(development, staging and production) are on same server then use namespace. In your initializers/sidekiq.rb file,

Sidekiq.configure_server do |config|
    config.redis = { url: 'redis://localhost:6379/0', namespace: "sidekiq_app_name_#{Rails.env}" }
end

Sidekiq.configure_client do |config|
    config.redis = { url: 'redis://localhost:6379/0', namespace: "sidekiq_app_name_#{Rails.env}" }
end     

这篇关于多环境的 Sidekiq 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆