0.0
No commit activity in last 3 years
No release in over 3 years
Adds a #deliver_asap method to Mail::Message that, using Rufus scheduler, delivers an email in the background. The mail is 'optimistically' delivered: if the application is shut down during delivery, the mail will not be sent.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.8
~> 10.0

Runtime

 Project Readme

deliver_asap

Adds a 'deliver_asap' method to Mail::Message. This method works as the 'deliver_now' method, but transmits the mail in the background instead. Useful if one is not really at the stage where it makes sense to pay for a worker dyno on Heroku, but wants a snappy user experience when sending a signup mail, for example.

Usage

When creating a user you could send an email, without keeping the user who just signed up waiting, by doing:

AccountMailer.welcome(@user).deliver_asap

This assumes an AccountMailer that looks something like this:

class AccountMailer < ApplicationMailer
  def welcome(user)
    @user = user
    mail(to: @user.email, subject: 'Welcome to a site')
  end
end

That is all.

Technical notes

This gem depends on Rufus scheduler to create a 'one-time' background job. The scheduler already takes care of limiting the number of running threads, which greatly simplifies the implementation of 'deliver_asap'.