Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sidekiq list all jobs [queued + running]

Tags:

Is there a way to get a list of all the jobs currently in the queue and running? Basically, I want to know if a job of given class is already there, I don't want to insert my other job. I've seen other option but I want to do it this way.

I can see here how to get the list of jobs in the queue.

queue = Sidekiq::Queue.new("mailer") queue.each do |job|   job.klass # => 'MyWorker' end 

from what I understand this will not include processing/running jobs. Any way to get them?

like image 555
aks Avatar asked Jan 19 '18 20:01

aks


People also ask

How do Sidekiq queues work?

It works the same way as the scheduled queue; it contains jobs that have to be executed at a given time in the future. The main difference is that in retries queue, jobs are added by the Sidekiq, and the time when the job should be executed is calculated based on the retries counter.

Is Sidekiq a queue?

Out-of-the-box Sidekiq uses a single queue named "default," but it's possible to create and use any number of other named queues if there is at least one Sidekiq worker configured to look at every queue.

How many jobs can Sidekiq handle?

Today Sidekiq uses a default concurrency of 25. These means Sidekiq will spawn 25 worker threads and execute up to 25 jobs concurrently in a process.


1 Answers

if you want to list all currently running jobs from console, try this

workers = Sidekiq::Workers.new workers.each do |_process_id, _thread_id, work|   p work end 

a work is a hash.

to list all queue data.

queues = Sidekiq::Queue.all queues.each do |queue|   queue.each do |job|     p job.klass, job.args, job.jid   end end 

for a specific queue change this to Sidekiq::Queue.new('queue_name')

similarly you can get all scheduled jobs using Sidekiq::ScheduledSet.new

like image 167
Haseeb A Avatar answered Sep 21 '22 05:09

Haseeb A