Created
May 8, 2013 15:38
-
-
Save jondeandres/5541308 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 WuakiBackground | |
module DelayedTask | |
def self.include(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def before_perform(*args) | |
_args = args.dup | |
options = _args.extract_options! | |
time = options[:time] | |
unless on_time?(time) | |
options[:time] = self.wait_until | |
_args << options | |
WuakiCommon::Queue.add(self, *_args) | |
raise Resque::DontPerform | |
end | |
end | |
def load_time(time) | |
Time.parse(time).utc | |
end | |
def on_time?(time) | |
if time | |
Time.now.utc > time | |
else | |
true | |
end | |
end | |
def wait_until | |
@wait_until ||= 1.minute.from_now | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment