Sending Devise emails through Resque

六月ゝ 毕业季﹏ 提交于 2019-12-05 01:35:51

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!