Skip to content

Instantly share code, notes, and snippets.

@zhengjia
Forked from scottwater/mail_queue.rb
Created July 30, 2011 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhengjia/1115064 to your computer and use it in GitHub Desktop.
Save zhengjia/1115064 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