Skip to content

Instantly share code, notes, and snippets.

@npj
Created May 20, 2012 13:00
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 npj/2758040 to your computer and use it in GitHub Desktop.
Save npj/2758040 to your computer and use it in GitHub Desktop.
# app/models/queue/base.rb
class Queue::Base
class << self
def enqueue(object, method, *args)
meta = { 'method' => method }
if is_model?(object)
Resque.enqueue(self, meta.merge('class' => object.class.name, 'id' => object.id), *args)
else
Resque.enqueue(self, meta.merge('class' => object.name), *args)
end
end
def perform(meta = { }, *args)
if meta.has_key?('id')
if model = meta['class'].constantize.find_by_id(meta['id'])
model.send(meta['method'], *args)
end
else
meta['class'].constantize.send(meta['method'], *args)
end
end
def is_model?(object)
object.class.respond_to?(:find_by_id)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment