Created
December 18, 2013 13:13
-
-
Save remvee/8022106 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Queue all email with delayed job automagically. | |
| module DelayedMailer | |
| extend ActiveSupport::Concern | |
| included do | |
| alias_method_chain :deliver, :delayed_job | |
| end | |
| class MailJob < Struct.new(:message) | |
| def perform | |
| message.deliver_without_delayed_job | |
| end | |
| end | |
| def deliver_with_delayed_job | |
| Delayed::Job.enqueue(MailJob.new(self)) | |
| self | |
| end | |
| end | |
| Mail::Message.send(:include, DelayedMailer) | |
| class ActionMailer::Base | |
| def self.delay(*args) | |
| raise "already queuing your email" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment