Search code examples
sidekiq

Difference between Worker#jobs and Sidekiq::Queue#size


I want to know if a queue is empty.

I see two ways of doing this. Assuming there is a Worker job:

  • Worker.jobs.size
  • Sidekiq::Queue.new('worker_queue').size

Are there significant differences between the two ways?


Solution

  • A worker is a thread that can execute jobs. You can have a million jobs enqueued but with sidekiq -c 5 you'll only have 5 workers processing those jobs.

    If you want to know if a queue is empty, use Sidekiq::Queue.new(name).size == 0.

    Related note: the Sidekiq::Worker module really should have been named Sidekiq::Job.