Search code examples
sidekiq

Sidekiq: how to pass a queue as a variable into a worker


I have a worker like so:

class MassDispatchServiceWorker
  include Sidekiq::Worker
  sidekiq_options queue: :bulk

  def perform(message_params)
    DispatchService.new(message_params).dispatch!
  end
end

However I have a need for the same exact method but to pass in a queue as a variable. Sometimes I want the queue to be bulk, other times I'll need something else. Is that possible with sidekiq?


Solution

  • Use the Sidekiq::Client API.

    Sidekiq::Client.push('class' => MassDispatchServiceWorker, 'args' => [], 'queue' => whatever)