-
-
Save zhengjia/1115064 to your computer and use it in GitHub Desktop.
A really simple general purpose mail queue for resque
This file contains 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
module MailQueue | |
extend self | |
def queue | |
:default | |
end | |
def perform(options = {}) | |
options = options.with_indifferent_access | |
mailer = options[:klass].constantize | |
method = options[:method] | |
mailer.send(method, *options[:args]).deliver | |
end | |
def enqueue() | |
EnqueueProxy.new(self) | |
end | |
class EnqueueProxy | |
def initialize(klass) | |
@klass = klass | |
end | |
def method_missing(m, *args, &block) | |
if @klass.respond_to? m | |
options = {:klass => @klass.to_s, :method => m, :args => args} | |
Resque.enqueue(MailQueue, options) | |
else | |
super | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment