Background notification not working with delayed_job
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.
You think you can work out a Pull Request for this?
Working on it right now. =)
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?
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?
+1
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.
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)
which is why you can do
ExceptionNotifier::Notifier.delay.background_exception_notification(e)
outside, not having to change the gem's code