Sidekiq 列出所有作业 [排队 + 正在运行] [英] Sidekiq list all jobs [queued + running]

查看:50
本文介绍了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

这篇关于Sidekiq 列出所有作业 [排队 + 正在运行]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆