Created
September 24, 2011 13:59
-
-
Save betawaffle/1239357 to your computer and use it in GitHub Desktop.
Resque + ActiveRecord
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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