1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Minor optimization to just enqueue something now if it's set to perform_in the past or now.

This commit is contained in:
Jonathan Hyman 2013-06-27 19:01:13 -04:00
parent f435bc33bf
commit d5bf8e2fb4

View file

@ -41,8 +41,15 @@ module Sidekiq
def perform_in(interval, *args)
int = interval.to_f
ts = (int < 1_000_000_000 ? Time.now.to_f + int : int)
client_push('class' => self, 'args' => args, 'at' => ts)
now = Time.now.to_f
ts = (int < 1_000_000_000 ? now + int : int)
# Optimization to enqueue something now that is scheduled to go out now or in the past
if ts <= now
perform_async(*args)
else
client_push('class' => self, 'args' => args, 'at' => ts)
end
end
alias_method :perform_at, :perform_in