If you’re building a website that supports user logins and use Devise to manage that, you’ll soon find out that it sends out emails synchronously by default. This is not a good practice, as it’s not something that a user visiting your site should have to wait for. There is a solution to make this work asynchronously, however.
There is a page in the Devise wiki that describes how to configure it for sending emails asynchronously. It involves using the devise-async gem and it’s rather flexible and supports Resque, Sidekiq and Delayed::Job. You should start by following the instructions on that page if you’re using Sidekiq.
However, there is a thing that you might overlook: by default it’ll enqueue the
jobs in the
mailer queue. This means you’ll have to either configure you Sidekiq worker to
look for jobs in that queue as well, or instruct devise-async to
enqueue in a different queue.
The latter is simple and is described in the README:
Configuring the Sidekiq worker to look into more than one queue is only slightly more complicated and looks something like the following:
1 2 3 4 5 6 7 8 9 10 11
You should save this as
config/sidekiq.yml and then restart the worker as well
as the server and then your emails will be sent asynchronously.