Skip to content

Instantly share code, notes, and snippets.

@grosser
Forked from scottwater/mail_queue.rb
Created April 28, 2011 05:37
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 grosser/945860 to your computer and use it in GitHub Desktop.
Save grosser/945860 to your computer and use it in GitHub Desktop.
Deliver mails delayed XXXMailer.delayed_foo(user, bar)
class ResqueGenericJob
def self.perform(options={})
options = options.with_indifferent_access
klass = options[:class]
method = options[:method]
if options.has_key?(:args)
klass.constantize.send(method, *options[:args])
else
klass.constantize.send(method)
end
end
end
class XXXMailer
def self.method_missing(name, *args)
if name.to_s =~ /^delayed_(.*)/
if args.last.is_a?(Hash)
queue = args.last.delete(:queue)
args.pop if args.last.empty?
end
options = {:args => args}
Resque::Job.create(queue, GenericJob, options.except(:queue).merge(:class => self.class.to_s, :method => "deliver_#{$1}"))
else
super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment