如何使用delayed_job查看排队作业的情况?
我一直在运行delayed_job并遇到一些错误,但现在我不知道作业队列中有什么或者它们发生了什么......
我怎样才能弄清楚这一点,以便我可以调试它是否能够执行已放入队列中的内容?
这是我调用该作业(它是 cron 任务的一部分)及其调用的邮件程序的地方:
class SomeMailJob < Struct.new(:contact, :contact_email)
def perform
OutboundMailer.deliver_campaign_email(contact,contact_email)
end
end
#class OutboundMailer < ActionMailer::Base
class OutboundMailer < Postage::Mailer
def campaign_email(contact,email)
subject email.subject
recipients contact.email
from 'Timothy Fong <[email protected]>'
sent_on Date.today
body :email => email
end
I have been running delayed_job and was hitting some errors, but now I don't know what is sitting in the job queue or what's going on with them....
How can I figure that out so I can debug whether it is able to execute what has been put in the queue?
Here is where I call the job (it is part of a cron task) and the mailer it calls:
class SomeMailJob < Struct.new(:contact, :contact_email)
def perform
OutboundMailer.deliver_campaign_email(contact,contact_email)
end
end
#class OutboundMailer < ActionMailer::Base
class OutboundMailer < Postage::Mailer
def campaign_email(contact,email)
subject email.subject
recipients contact.email
from 'Timothy Fong <[email protected]>'
sent_on Date.today
body :email => email
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过Delayed::Job模型深入了解您的delayed_job队列(我认为它的名称可能在以后的版本中发生了变化)。它只是一个 ActiveRecord 模型,您可以执行对普通模型所做的所有操作。查找所有,查找设置了
failed_at
的,查找设置了locked_by
的(当前正在处理)。我发现如果您先从控制台 to_yaml 它们,它们会更容易阅读:
y Delayed::Job.all
。You can gain insight into your delayed_job queue through the Delayed::Job model (I think the name of it might have changed in later versions). It's just an ActiveRecord model and you can do all the things you'd do to a normal one. Find all, find ones with
failed_at
set, find ones withlocked_by
set (currently being worked).I find they're much easier to read if you to_yaml them first:
y Delayed::Job.all
from console.您必须小心设置
Delayed::Job.destroy_failed_jobs = false
因为默认情况下,尝试 25 次后作业将被删除。然后您可以看到哪些作业失败了(以及 failed_at 字段中的时间)。有一个耙子任务来清理它们。另一个值得关注的队列是 Resque,它附带了一个用于监控队列的小型管理应用程序。 其介绍值得一读。
You have to be careful to set
Delayed::Job.destroy_failed_jobs = false
because by default after 25 tries a job will be deleted. Then you can see which jobs failed (and what time in the failed_at field). There's a rake task to clean them up.Another queue to look at is Resque, which comes with a little management app to monitor queues. Its introduction is a good read.