Question

My application uses the Collective Idea fork of Delayed Job to send email asynchronously. The problem is that this works fine in the development environment but not in production. The jobs aren't failing (I've checked the delayed_jobs table), they're just not being consumed. There is nothing of note in the production log.

This is the contents of the handler column within the delayed_jobs table:

--- !ruby/struct:Delayed::PerformableMethod \
object: CLASS:FeedbackMailer\
method: :deliver_message\
args: \
- AR:Message:6\

—I can't see anything wrong there. This is my FeedbackMailer class:

class FeedbackMailer < ActionMailer::Base
  def message(message, sent_at = Time.now)
    subject = 'New Feedback Message'
    subject = "#{subject}: #{message.subject}" if message.subject.present?
    subject    subject
    recipients 'me@example.org'
    from       'feedback@example.org'
    sent_on    sent_at
    body       :message => message
  end
end 

Finally, this is the relevant method in my Message class:

def send_email
  FeedbackMailer.send_later(:deliver_message, self)
end

I know that the ActionMailer code works correctly in production because I've tested it synchronously before switching to Delayed Job. As I said, I've also run it all the way through successfully using Delayed Job in development.

If I run the top command on the server then I can see the Delayed Job Ruby process coming alive every five seconds. How can I debug this?

Was it helpful?

Solution

John,

While I too used the collective Idea fork, I found that Tobi's script works too. I just need a tmp/pid directory (which you may have) and you get the log file and can cross reference this file with what your error column says in your Delayed::Job.first record (or whatever job it is of course). Script for running as a daemon from tobi fork

Oh, and you did restart, if you made changes right? Had to ask.

OTHER TIPS

Do you run ./script/delayed_job with the -e production flag set?

Does anything appear in log/delayed_job.log? You mentioned the production log, but delayed job has its own log.

  • [JOB] acquiring lock on PreviewImageJob

You might try making a separate class instead of using the _later() method.

class PreviewImageJob < Struct.new(:item_id)
  def perform
    item = Item.find(item_id)
    item.generate_interior_images!
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top