Clay
Clay

Reputation: 2999

Delayed_job not sending Rails 3 emails

Note: Using Rails 3.1 and current delayed_job gem.

I have a User model that calls after_create :mail_confirmation.

The mail_confirmation method looks like the following, per the delayed_job instructions:

def mail_confirmation
    UserMailer.delay.registration_confirmation(self)
end

The UserMailer is:

class UserMailer < ActionMailer::Base
  default from: "[email protected]"

  def registration_confirmation(user)
    @user = user
    mail(:to => "#{user.full_name} <#{user.email}>", :subject => "Test registration email")
  end
end

The job is queued, and the output from rake jobs:work makes it seem as if it completed successfully:

[Worker(host:mymac.local pid:73694)] Starting job worker
[Worker(host:mymac.local pid:73694)] Class#registration_confirmation completed after 1.3659
[Worker(host:mymac.local pid:73694)] 1 jobs processed at 0.7288 j/s, 0 failed ...

There is no error but the email is never sent. It works fine if I remove delayed from the method call in the User model and go with the standard deliver method:

def mail_confirmation
    UserMailer.registration_confirmation(self).deliver
end

How can I find out what is happening when the job is processed? Any idea how to fix it?


Update It appears that it is related to this:

NoMethodError with delayed_job (collectiveidea gem)

Upvotes: 3

Views: 3531

Answers (2)

Rodrigo Souto
Rodrigo Souto

Reputation: 43

I'm having the same issues here. I discovered that for some reason the delay method called on Mailer classes is being handled by the method Delayed::MessageSending#delay instead of Delayed::DelayMail#delay which instantiates the right performable (which is PerformableMailer instead of PerformableMethod). It doesn't crash the job because PerformableMethod just calls the method without the deliver.

Take a look at:

  • delayted_job/lib/delayed/message_sending.rb
  • delayted_job/lib/delayed/performable_mailer.rb

Upvotes: 0

Pete
Pete

Reputation: 1482

Yeah i had this same issue. @Clay is correct, there is an issue at the moment: https://github.com/collectiveidea/delayed_job/issues/323

I resolved this problem by reverting back to the previous version of delayed_job.

gem 'delayed_job', '2.1.2'

Upvotes: 1

Related Questions