I'm trying to send Devise emails through Resque.
Regular emails are getting sent through Resque just fine. And Devise emails are sent just fine, but not Devise emails through Resque. I get "Could not find a valid mapping" which implies that my helper overrides aren't getting picked up.
I'm following this http://shaker.4-dogs.biz/2011/08/06/using-resque-to-send-mail-for-devise/
The odd thing is that to debug it I'm using a local copy of Devise and adding breakpoints in 'initialize_from_record' in Devise, which gets hit when I just use Devise alone. But when I send the Devise emails through resque the breakpoints don't get hit:
class ResqueMailer < Devise::Mailer
include Resque::Mailer
end
config.mailer = "ResqueMailer"
And resque instead shows a packaged gem path and not my local source such as:
/Users/mm/.rvm/gems/ruby-1.9.2-p290@evergreen/gems/devise-1.4.9/lib/devise/mailers/helpers.rb:20:in `devise_mail'
Any idea why it's not using my local gem source AND/OR how to get Resque to send my Devise emails?
An easy way is to use the devise-async gem.
Add the gem to your Gemfile
# Gemfile
gem "devise-async"
Configure Devise to use the proxy mailer.
# config/initializers/devise.rb
config.mailer = "Devise::Async::Proxy"
[Optional] And finally tell DeviseAsync to use Resque to enqueue the emails.
# config/initializers/devise_async.rb
Devise::Async.backend = :resque
The gem also supports Sidekiq and Delayed::Job.
Update: you do not need to do this with resque_mailer
>= 2.2.3
The monkey patch at https://github.com/devton/resqued_devise_mailer did not work since it sends the full model as an argument to Resque, which will end up marshaling the object and is frowned upon (see Persistence on https://github.com/defunkt/resque).
Here's what worked for me:
Use the resque_mailer gem: https://github.com/zapnap/resque_mailer
gem 'resque_mailer'
Add lib/devise_resque_mailer.rb: see https://gist.github.com/1375726
That creates a new DeviseResqueMailer class that will not change any existing behavior in Resque::Mailer, so you can use that module in other mailers.
config/initializers/devise.rb:
Devise.setup do |config|
require 'devise_resque_mailer'
config.mailer = "DeviseResqueMailer"
Move your devise views from app/views/devise/mailer/ to app/views/devise_resque_mailer/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With