Codebeerstartups

Every Dog has one Blog

How to Send Devise Emails via Delayed Job or Rescue or Any Other Background Jobs

All always prefer to use devise in my application. But the problem is emails. Devise send emails synchronously but if you want to send then asynchronously here is a quick tip for you. Use devise-async gem.

Installation

1
gem 'devise-async'

Now enable module in your model ie

1
2
3
class User < ActiveRecord::Base
  devise :database_authenticatable, :async, :confirmable # etc ...
end

By default devise-asyn use resque so if you are not using resque then set your queuing backend by creating config/initializers/devise_async.rb:

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

Thats it. Now this will send all the devise emails via delayed job or rescue or any other background jobs.

Make sure your devise-asyn gem is below devise gem else you will get an error like:

1
/Users/me/.rvm/gems/custom_gem_set/gems/devise-async-0.5.1/lib/devise/async.rb:47:in `': undefined method `add_module' for Devise:Module (NoMethodError)

Comments