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:
Then tell Devise to use the proxy mailer in
And last but not least, set your queuing backend by creating
Your notification emails should now be gracefully enqueued for background processing.
gem "devise-async"
config/initializers/devise.rb
:
# Configure the class responsible to send e-mails. config.mailer = "Devise::Async::Proxy"
config/initializers/devise_async.rb
:
# Supported options: :resque, :sidekiq, :delayed_job Devise::Async.backend = :resque
## Notice I have jobs in queue but no workers. Do I have to create task, or workers?
#!/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