Skip to content

Instantly share code, notes, and snippets.

@jondeandres
Created May 8, 2013 15:38
Show Gist options
  • Save jondeandres/5541308 to your computer and use it in GitHub Desktop.
Save jondeandres/5541308 to your computer and use it in GitHub Desktop.
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