开发者

How do I see what's going on with queued jobs using delayed_job?

开发者 https://www.devze.com 2023-01-17 03:00 出处:网络
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....

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 开发者_Go百科campaign_email(contact,email)
    subject    email.subject
    recipients contact.email
    from       'Timothy Fong <tim.fong@opshub.com>'
    sent_on    Date.today

    body       :email => email
  end


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 with locked_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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消