Sidekiq list all jobs [queued + running]

后端 未结 3 1153
悲哀的现实
悲哀的现实 2021-02-04 05:33

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 o

相关标签:
3条回答
  • 2021-02-04 06:09

    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

    0 讨论(0)
  • 2021-02-04 06:10

    Assuming you passed the Hash as the argument to Sidekiq when you enqueued.

    args = {
      "student_id": 1,
      "student_name": "Michael Moore"
        }
    
    YourWorker.perform_in(1.second,args)
    

    Then anywhere from your application, you could retrieve it as following

          ss = Sidekiq::ScheduledSet.new
          student_id_list = ss.map{|job| job['args'].first["student_id"]}
    
    0 讨论(0)
  • 2021-02-04 06:13

    running jobs:

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

    queued jobs across all queues:

    Sidekiq::Queue.all.each do |queue|
      # p queue.name, queue.size
      queue.each do |job|
        p job.klass, job.args
      end
    end
    
    0 讨论(0)
提交回复
热议问题