Created
February 19, 2010 17:50
-
-
Save terrbear/308975 to your computer and use it in GitHub Desktop.
This file contains 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 Jobs | |
module ScheduledJob | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
def perform_with_schedule | |
Delayed::Job.enqueue self, 0, self.class.schedule.from_now.getutc | |
perform_without_schedule | |
end | |
module ClassMethods | |
def method_added(name) | |
if name.to_s == "perform" && !@redefined | |
@redefined = true | |
alias_method_chain :perform, :schedule | |
end | |
end | |
def schedule | |
@schedule | |
end | |
def run_every(time) | |
@schedule = time | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment