Sidekiq 列出所有作业 [排队 + 正在运行]

问题描述:

有没有办法获取当前在队列中并正在运行的所有作业的列表?基本上,我想知道给定班级的工作是否已经存在,我不想插入我的其他工作.我已经看到了其他选项,但我想这样做.

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?

如果你想从控制台列出所有当前正在运行的作业,试试这个

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

work 是一个哈希值.

列出所有队列数据.

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

对于特定队列,将其更改为 Sidekiq::Queue.new('queue_name')

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

同样,您可以使用 Sidekiq::ScheduledSet.new