Ruby-on-rails 多环境的 Sidekiq 配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15260634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sidekiq configuration for multiple environments
提问by user1687078
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.
我查看了多个来源并尝试了各种场景,但无法解决此问题,因此出现了问题。请指出我正确的方向。
Like everybody I have 3 env (development, staging and production).
像每个人一样,我有 3 个 env(开发、登台和生产)。
I have the following in my sidekiq.yml file
我的 sidekiq.yml 文件中有以下内容
# 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]
With this I was hoping that when I start sidekiq with the command
有了这个,我希望当我用命令启动 sidekiq 时
RAILS_ENV=#{rails_env} bundle exec sidekiq -C config/sidekiq.yml
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.
它将从配置文件中获取所有值并使用适当的队列和日志文件启动 sidekiq,但它不起作用。Sidekiq 启动但它只创建 stg_xyz_tests_queue、stg_default_xyz_queue 和 stg_xyz_default_queue,无论我们使用什么环境。
The other approach I tried was using the following code in the config/environments/development.rb
我尝试的另一种方法是在 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
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.
这样,队列就可以正常创建了,但是没有创建或写入日志文件,我需要为所有 3 个环境复制此代码。
What is the best way to get sidekiq working seamlessly for my setup Thanks for your help in advance !!!
让 sidekiq 为我的设置无缝工作的最佳方法是什么提前感谢您的帮助!!!
回答by Ranjithkumar Ravi
Use -e option
使用 -e 选项
bundle exec sidekiq -e beta -C config/sidekiq.yml
If all environments(development, staging and production) are on same server then use namespace. In your initializers/sidekiq.rb file,
如果所有环境(开发、登台和生产)都在同一台服务器上,则使用命名空间。在您的 initializers/sidekiq.rb 文件中,
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
回答by user1687078
回答by Darpan Chhatravala
Use to set log, and environment support:
用于设置日志,环境支持:
bundle exec sidekiq -d -L log/sidekiq.log -e production -C config/sidekiq.yml

