exception_notification icon indicating copy to clipboard operation
exception_notification copied to clipboard

Background notification not working with delayed_job

Open victorbueno opened this issue 14 years ago • 8 comments

From delayed job instructions:

Due to how mailers are implemented in Rails 3, we had to do a little work around to get delayed_job to work.

without delayed_job

Notifier.signup(@user).deliver

with delayed_job

Notifier.delay.signup(@user) Remove the .deliver method to make it work. It’s not ideal, but it’s the best we could do for now.

The method that sends the background_notification is using the deliver option. See:

mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format| format.text { render "#{mailer_name}/background_exception_notification" } end.deliver

This method should be written using 'delay' instead of deliver to make it work with delayed_job.

victorbueno avatar Mar 21 '12 18:03 victorbueno

You think you can work out a Pull Request for this?

smartinez87 avatar Mar 22 '12 14:03 smartinez87

Working on it right now. =)

victorbueno avatar Mar 22 '12 14:03 victorbueno

Any update on this? I'd like to send emails through dealyed_job. I've checked victorbueno's repository, he patched background_notification to use delay instead of deliver. This has not been pushed into this repository and it seems that the official gem grabs from here. For my deploy I prefer using official gems. Any solutions to this? Will the change be pulled?

bragma avatar May 16 '12 18:05 bragma

is this working now? can i set delayed_job as the default, or do i need to manually call exception_notification() with the relevant option?

emiltin avatar Jun 28 '12 18:06 emiltin

+1

threadhead avatar Jul 07 '12 02:07 threadhead

IMO, this is rather a DelayedJob issue. ExceptionNotification is implemented according Action Mailer API. I don't want to do a work around to make it work with other's work around. Plus it will only work with DJ if I do so, breaking it for other background job processing libraries.

smartinez87 avatar Jul 07 '12 19:07 smartinez87

Wouldn't it just work by wrapping the notification with an instance method?

class User < ActiveRecord::Base
  def signup!
    Notifier.signup(self).deliver
  end
end

@user.delay.signup!

or in a more generic form:

class User < ActiveRecord::Base
  def async_notify(notification)
    Notifier.send(notification, self).deliver
  end
end

@user.delay.async_notify(:signup)

moiristo avatar Jul 09 '12 14:07 moiristo

which is why you can do

ExceptionNotifier::Notifier.delay.background_exception_notification(e)

outside, not having to change the gem's code

smartinez87 avatar Jul 09 '12 14:07 smartinez87