Devise Async provides an easy way to configure Devise to send its emails asynchronously using your preferred queuing backend.
##This is an minimal version of devise-async
Add this line to your application's Gemfile:
gem 'devise-async'
And then execute:
$ bundle
Or install it yourself as:
$ gem install devise-async
Add :async
to the devise
call in your model:
class User < ActiveRecord::Base
devise :database_authenticatable, :async, :confirmable # etc ...
end
Set your queuing backend by creating config/initializers/devise_async.rb
:
# Supported options: :resque, :sidekiq, :delayed_job, :queue_classic, :torquebox, :backburner, :que, :sucker_punch
Devise::Async.backend = :resque
Tip: it defaults to Resque. You don't need to create the initializer if using it.
The gem can be enabled/disabled easily via config, for example based on environment.
# config/initializers/devise_async.rb
Devise::Async.enabled = true # | false
Customize Devise.mailer
at will and devise-async
will honor it.
Upgrade note: if you're upgrading from any version < 0.6 and getting errors
trying to set Devise::Async.mailer
just use Devise.mailer
instead.
Let you specify a custom queue where to enqueue your background Devise jobs. Defaults to :mailer.
# config/initializers/devise_async.rb
Devise::Async.queue = :my_custom_queue
You can specify a custom priority for created background jobs in Devise or Backburner. If no value is specified, jobs will be enqueued with whatever default priority is configured in Devise or Backburner.
# config/initializers/devise_async.rb
Devise::Async.priority = 10
To avoid repeating Devise::Async
in the initializer file you can use the block syntax
similar to what Devise
offers.
# config/initializers/devise_async.rb
Devise::Async.setup do |config|
config.enabled = true
config.backend = :resque
config.queue = :my_custom_queue
end
If you are using Sidekiq and your jobs are enqueued but not processed you might need to set a queue explicitly:
# config/initializers/devise_async.rb
Devise::Async.setup do |config|
config.backend = :sidekiq
config.queue = :default
end
Be aware that since version 0.3.0 devise-async enqueues the background job in active
record's after_commit
hook. If you're using rspec's use_transactional_fixtures
the jobs
might not be enqueued as you'd expect.
More details in this stackoverflow thread.
Older versions of Devise are supported in the devise_2_1 branch and in the 0.5 series of devise-async.
Please refer to that branch README for further info.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Released under the MIT License. See the LICENSE file for further details.