Skip to content

Instantly share code, notes, and snippets.

@scottwater
Created April 26, 2011 14:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save scottwater/942341 to your computer and use it in GitHub Desktop.
Save scottwater/942341 to your computer and use it in GitHub Desktop.
A really simple general purpose mail queue for resque
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