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:
parent
f435bc33bf
commit
d5bf8e2fb4
1 changed files with 9 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue