Codebeerstartups

How to send devise emails via delayed job or rescue or any other background jobs

Introduction

user

Mohit Jain

Rails Developer


optimization performance tips-and-tricks

How to send devise emails via delayed job or rescue or any other background jobs

Posted by Mohit Jain on .
Featured

optimization performance tips-and-tricks

How to send devise emails via delayed job or rescue or any other background jobs

Posted by Mohit Jain on .

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

gem 'devise-async'

Now enable module in your model ie

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:

# 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:

/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)
user

Mohit Jain

http://codebeerstartups.com

Rails Developer