Scott Watermasysk

Still Learning to Code

Resque Mail Queue Gem

I have written two times (Simple Resque Mail Queue and Simple Resque Mail Queue II) before about a simple module MailQueue which can be used to easily send email asynchronously with Resque.

Thanks to Les Hill’s really simple instructions on writing your own gemspec, I have finally published it as a ruby gem: resque_mail_queue.

Assuming you already have Resque installed, to use it, you simply need to add this to your GemFile:

1
gem 'resque\_mail\_queue'

From there, similar to the previous examples, to use it simply add enqueue before you Action Mailer methods:

1
UserMailer.enqueue.welcome_email(1)

The version is set at 0.2.0, but I am not expecting too many changes. I will bump it to 1.0 as soon as I add a custom matcher for cleaner specs and get some additional outside feedback.

If you are using the previous Gist versions, here are the changes I made:

  1. No dependency on Active Support. This is probably not a big deal for most rails projects, but less dependencies is always a good thing.
  2. The object passed to Resque is now the mailer class instead of MailQueue. This makes specs a little cleaner to read since you are referencing the actual mailer.
  3. The queue the emails are placed in can now be changed per mailer.
  4. The module is now injected into ActionMailer::Base and available on all of your mailers.

This was my first real gem. So if you see anything odd in it, please let me know.