From 83893aa12255559385a7ebc892162619eaf0bcf2 Mon Sep 17 00:00:00 2001 From: Evan Prothro Date: Fri, 1 Aug 2014 14:56:51 -0500 Subject: [PATCH] fixup to poll_interval logic, so calling poll_interval= has expected behavior --- lib/sidekiq/scheduled.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sidekiq/scheduled.rb b/lib/sidekiq/scheduled.rb index a29e941a..97147066 100644 --- a/lib/sidekiq/scheduled.rb +++ b/lib/sidekiq/scheduled.rb @@ -51,7 +51,10 @@ module Sidekiq logger.error ex.backtrace.first end - after(poll_interval * rand) { poll } + # Randomizing scales the interval by half since + # on average calling `rand` returns 0.5. + # We make up for this by doubling the interval + after(poll_interval * 2 * rand) { poll } end end @@ -73,7 +76,7 @@ module Sidekiq def poll_interval Sidekiq.options[:poll_interval] ||= begin pcount = Sidekiq.redis {|c| c.scard('processes') } || 1 - pcount * 15 * 2 + pcount * 15 end end