我已经看过多个来源,并尝试了各种场景,但无法解决这个问题.请指出正确的方向.
像所有人都有3 env(开发,分期和生产).
# 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
RAILS_ENV=#{rails_env} bundle exec sidekiq -C config/sidekiq.yml
它将从配置文件中获取所有值,并使用log / sidekiq.log中的相应队列和日志文件启动sidekiq,但这不起作用.
Sidekiq启动,但它只创建stg_xyz_tests_queue,stg_default_xyz_queue和stg_xyz_default_queue,无论我们使用什么环境.
我尝试的另一种方法是在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个环境.
什么是最好的方式让sidekiq为我的设置无缝工作
感谢您的帮助提前!
解决方法
使用-e选项
bundle exec sidekiq -e beta -C config/sidekiq.yml
如果所有环境(开发,分期和生产)都在同一个服务器上,那么使用命名空间.在你的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