Rails + Sidekiq: Sidekiq.options[:concurrency] returns 10 instead of 3, which is the value in my config/sidekiq.yml file
Asked Answered
V

1

6

I use Sidekiq with Rails and the concurrency value returned appears to be wrong. Sidekiq.options[:concurrency] returns 10 instead of 3, which is the value in my config/sidekiq.yml file:

:concurrency: 3
staging:
  :concurrency: 3
production:
  :concurrency: 3
:queues:
  - critical
  - default
  - low

Why is the wrong value being returned?

Vogul answered 3/11, 2019 at 20:7 Comment(0)
C
6
  • Don't trust what you see in the Rails console. (because Rails isn't going to read config/sidekiq.yml, it doesn't need to know about those settings)

  • Trust what you see in the Sidekiq console. (because when sidekiq starts it reads config/sidekiq.yml to apply its settings)

Given an example worker:

class ExampleWorker
  include Sidekiq::Worker

  def perform
    puts Sidekiq.options[:concurrency]
  end
end

Open a Rails console and run the job synchronously:

ExampleWorker.new.perform
10

This is the default.

Now run it asynchronously:

ExampleWorker.perform_async
 => "628773ecad22c4b19e4d08a4"

Open Sidekiq and wait for the job to run:

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 is applying the setting properly.

Carpogonium answered 3/11, 2019 at 23:4 Comment(1)
I figured I shouldn't trust the console due to the .yml files not being initialized, but I thought that I could put in a controller "raise Sidekiq.options[:concurrency].inspect". I didn't realize the sidekiq.yml file was only loaded when running sidekiq itself. Thanks!Vogul

© 2022 - 2024 — McMap. All rights reserved.