Using Resque to send mail for Devise

Since sending email synchronously is not a good idea, you’ll probably want to have Devise enqueuing it’s notification emails for background processing.

Although Devise doesn’t support this out of the box you can achieve it easily by using the devise-async gem.

To do so, first add it to your Gemfile:

gem "devise-async"

Then tell Devise to use the proxy mailer in config/initializers/devise.rb:

# Configure the class responsible to send e-mails.
config.mailer = "Devise::Async::Proxy"

And last but not least, set your queuing backend by creating config/initializers/devise_async.rb:

# Supported options: :resque, :sidekiq, :delayed_job
Devise::Async.backend = :resque

Your notification emails should now be gracefully enqueued for background processing.

 

#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path(‘../config/application’, __FILE__)
require ‘resque/tasks’

Askjane::Application.load_tasks

task “resque:setup” => :environment do
ENV['QUEUE'] ||= ‘*’
#for redistogo on heroku http://stackoverflow.com/questions/2611747/rails-resque-workers-fail-with-pgerror-server-closed-the-connection-unexpectedl
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
####run below command
#QUEUE=* rake environment resque:work