Ruby on rails 轨道&x2B;Sidekiq:Sidekiq.options[:concurrency]返回10而不是3,这是我的config/Sidekiq.yml文件中的值

Ruby on rails 轨道&x2B;Sidekiq:Sidekiq.options[:concurrency]返回10而不是3,这是我的config/Sidekiq.yml文件中的值,ruby-on-rails,ruby,ruby-on-rails-5,sidekiq,Ruby On Rails,Ruby,Ruby On Rails 5,Sidekiq,我将Sidekiq与Rails一起使用,返回的并发值似乎是错误的Sidekiq.options[:concurrency]返回10而不是3,这是我的config/Sidekiq.yml文件中的值: :concurrency: 3 staging: :concurrency: 3 production: :concurrency: 3 :queues: - critical - default - low 为什么返回了错误的值? 不要相信在Rails控制台中看到的内容。(因为

我将Sidekiq与Rails一起使用,返回的并发值似乎是错误的
Sidekiq.options[:concurrency]
返回10而不是3,这是我的
config/Sidekiq.yml
文件中的值:

:concurrency: 3
staging:
  :concurrency: 3
production:
  :concurrency: 3
:queues:
  - critical
  - default
  - low
为什么返回了错误的值?

  • 不要相信在Rails控制台中看到的内容。(因为Rails不会读取
    config/sidekiq.yml
    ,所以它不需要知道这些设置)

  • 相信你在Sidekiq控制台中看到的。(因为当sidekiq启动时,它读取
    config/sidekiq.yml
    以应用其设置)

举一个工人的例子:

class ExampleWorker
  include Sidekiq::Worker

  def perform
    puts Sidekiq.options[:concurrency]
  end
end
打开Rails控制台并同步运行作业:

ExampleWorker.new.perform
10
ExampleWorker.perform_async
 => "628773ecad22c4b19e4d08a4"
这是

现在异步运行它:

ExampleWorker.new.perform
10
ExampleWorker.perform_async
 => "628773ecad22c4b19e4d08a4"
打开Sidekiq并等待作业运行:

2019-11-03T22:59:13.786Z pid=2663 tid=ovyfd5os3 INFO: Running in ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin19]
2019-11-03T22:59:13.786Z pid=2663 tid=ovyfd5os3 INFO: See LICENSE and the LGPL-3.0 for licensing details.
2019-11-03T22:59:13.786Z pid=2663 tid=ovyfd5os3 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2019-11-03T22:59:13.786Z pid=2663 tid=ovyfd5os3 INFO: Booting Sidekiq 6.0.3 with redis options {:id=>"Sidekiq-server-PID-2663", :url=>nil}
2019-11-03T22:59:13.803Z pid=2663 tid=ovyfd5os3 INFO: Starting processing, hit Ctrl-C to stop
2019-11-03T22:59:18.176Z pid=2663 tid=ovyfdnd37 class=ExampleWorker jid=628773ecad22c4b19e4d08a4 INFO: start
3
2019-11-03T22:59:18.279Z pid=2663 tid=ovyfdnd37 class=ExampleWorker jid=628773ecad22c4b19e4d08a4 elapsed=0.104 INFO: done

Sidekiq正确地应用了设置。

我想我不应该信任控制台,因为.yml文件没有初始化,但我想我可以加入一个控制器“raise Sidekiq.options[:concurrency].inspect”。我没有意识到sidekiq.yml文件只在运行sidekiq时加载。谢谢