Skip to content

Instantly share code, notes, and snippets.

@betawaffle
Created September 24, 2011 13:59
Show Gist options
  • Save betawaffle/1239357 to your computer and use it in GitHub Desktop.
Save betawaffle/1239357 to your computer and use it in GitHub Desktop.
Resque + ActiveRecord
module Performable
def self.included(receiver)
# TODO: Raise exception if receiver doesn't implement perform
# unless receiver.method_defined? :perform
# raise ...
# end
receiver.class_eval do
def self.perform(id)
find(id).perform
end
def self.enqueue(*args)
create(*args).enqueue
end
end
receiver.class_eval do
@queue = self.to_s.tableize.to_sym
def enqueue
Resque.enqueue self.class, self.id
end
end
# unless receiver.instance_variable_defined? :@queue
# receiver.instance_variable_set :@queue, receiver.to_s.tableize.to_sym
# end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment