sidekiq_alive icon indicating copy to clipboard operation
sidekiq_alive copied to clipboard

queue_prefix config not used

Open c2ofh opened this issue 4 years ago • 6 comments

I wanted to use the queue_prefix for the queues, but the name is still "sidekiq_alive-:hostname"

init:

SidekiqAlive.setup do |config|
  config.queue_prefix = :x_alive
  config.server = 'puma'
end

I want to move this queues in all displays to the end, cause they normally sorted by name.

image

c2ofh avatar Jul 22 '20 21:07 c2ofh

Do you have a workaround ? working patch ?

Startouf avatar Sep 24 '21 12:09 Startouf

@Startouf no the name is still default. I just live with this bug.

c2ofh avatar Sep 27 '21 07:09 c2ofh

@c2ofh I've been looking at the code and I believe this may be a problem related to the startup sequence. Where did you put your init code ? Is it, by any chance, in an initializer that would run before/after a sidekiq initializer ?

@arturictus where do you put your sidekiq alive init code ?

I have an initializer that may interfere in my rails app.

# config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
  table_name_prefix = ::ActiveJob::Base.queue_name_prefix
  table_name_delimiter = ::ActiveJob::Base.queue_name_delimiter

  config.options[:queues] = config.options[:queues].map do |queue_name|
    [table_name_prefix, queue_name].compact.join(table_name_delimiter)
  end

  config.redis = {
    url: ENV["SIDEKIQ_REDIS_URL"],
    password: ENV["SIDEKIQ_REDIS_PASSWORD"]
  }
end

Startouf avatar Sep 30 '21 15:09 Startouf

Hi @Startouf, You can review the configurations here: https://github.com/arturictus/sidekiq_alive/blob/master/lib/sidekiq_alive.rb#L10-L36 I do not know what is the configuration result with the code above. Can you inspect in a worker Sidekiq.options and paste it here? I put my sidekiq_alive.rb in initializers folder. Thanks

arturictus avatar Oct 02 '21 17:10 arturictus

My sidekiq options look like this

irb(main):001:0> Sidekiq.options
=> 
{:queues=>[],
 :labels=>[],
 :concurrency=>10,
 :require=>".",
 :strict=>true,
 :environment=>nil,
 :timeout=>25,
 :poll_interval_average=>nil,
 :average_scheduled_poll_interval=>5,
 :error_handlers=>[#<Sidekiq::ExceptionHandler::Logger:0x000055da49937a00>],
 :death_handlers=>[],
 :lifecycle_events=>{:startup=>[], :quiet=>[], :shutdown=>[], :heartbeat=>[]},
 :dead_max_jobs=>10000,
 :dead_timeout_in_seconds=>15552000,
 :reloader=>#<Proc:0x000055da48f14500 /usr/local/bundle/gems/sidekiq-6.2.2/lib/sidekiq.rb:38>}

There should be something in the lifecycle hooks ?

I have

  • config/initializers/sidekiq.rb (with the code I pasted in my comment above)
  • config/initializers/sidekiq_alive.rb with
SidekiqAlive.setup do |config|
  config.server = 'puma'
  config.queue_prefix = "#{::ActiveJob::Base.queue_name_prefix}_z_sidekiq_alive"
end

Sidekiq alive does start with puma, so at least my settings are working partly

I am starting sidekiq in kubernetes using bundle exec sidekiq -C config/sidekiq.yml

The workers registered the good queue in sidekiq, when I go to the sidekiq UI, in busy I see my servers with Queues: MyApp_production_sidekiq_alive-hermes-sidekiq-64fd9f9fb9-95vsk, which correspond to my hostname + prefix (but as you can see not the prefix I added in sidekiq_alive). The problem is that the jobs are enqueued (at least the first job) on queues without the prefix sidekiq_alive-hermes-sidekiq-64fd9f9fb9-95vsk

EDIT

When I open a shell and I SidekiqAlive.current_queue, it returns something like => "MyApp_staging_z_sidekiq_alive-hermes-sidekiq-55fbf9bf8f-zdbvm" so I believe the config is only applied after SidekiqAlive has initialized and registered itself, which is causing the problem

Startouf avatar Oct 03 '21 10:10 Startouf

I was able to fix the problem by moving the SidekiqAlive::Worker.sidekiq_options queue: current_queue line into the sq_config.on(:startup) do block, I'm not sure this may affect existing installations or not, I have opened the above PR and it would be helpful if people with an existing sidekiq alive installation could test this new config to confirm whether it affects them or not

Startouf avatar Oct 04 '21 09:10 Startouf