Thursday, 18 December 2014

12 Tips of Christmas - 8 Send Emails with Sidekiq

12 Tips of Christmas - 8 Send Emails with Sidekiq

To help ensure users get a fast experience within your application, one tool you can utilise is Sidekiq to process any sending of email you might be doing asynchronously. 
To get started, just add the following line to your Gemfile
gem 'sidekiq'
You'll also need redis, so if you haven't got that installed run the following:
$ brew update

$ brew install redis

$ redis-server /usr/local/etc/redis.conf
To run Sidekiq:
$ bundle exec sidekiq
Sidekiq supports sending emails with ActionMailer off the bat, all you need to do is call delay before your mailer method instead of using deliver eg:
UserMailer.delay.reminder(@user)
We can also call delay_until to delay the email send until a specified time.
All too easy

No comments:

Post a Comment