From 314a6b64f8a1ca578dec6533e6fea05df5947f76 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Wed, 7 Oct 2015 09:43:08 -0700 Subject: [PATCH] Garbage optimizations --- lib/sidekiq/fetch.rb | 16 ++++++++++++---- lib/sidekiq/scheduled.rb | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/sidekiq/fetch.rb b/lib/sidekiq/fetch.rb index 8d554a5a..1d500f48 100644 --- a/lib/sidekiq/fetch.rb +++ b/lib/sidekiq/fetch.rb @@ -120,7 +120,10 @@ module Sidekiq def initialize(options) @strictly_ordered_queues = !!options[:strict] @queues = options[:queues].map { |q| "queue:#{q}" } - @unique_queues = @queues.uniq + if @strictly_ordered_queues + @queues = @queues.uniq + @queues << Sidekiq::Fetcher::TIMEOUT + end end def retrieve_work @@ -158,7 +161,7 @@ module Sidekiq end def queue_name - queue.gsub(/.*queue:/, '') + queue.gsub(/.*queue:/, ''.freeze) end def requeue @@ -174,8 +177,13 @@ module Sidekiq # recreate the queue command each time we invoke Redis#brpop # to honor weights and avoid queue starvation. def queues_cmd - queues = @strictly_ordered_queues ? @unique_queues.dup : @queues.shuffle.uniq - queues << Sidekiq::Fetcher::TIMEOUT + if @strictly_ordered_queues + @queues + else + queues = @queues.shuffle.uniq + queues << Sidekiq::Fetcher::TIMEOUT + queues + end end end end diff --git a/lib/sidekiq/scheduled.rb b/lib/sidekiq/scheduled.rb index 0f45fe76..fae3b095 100644 --- a/lib/sidekiq/scheduled.rb +++ b/lib/sidekiq/scheduled.rb @@ -16,7 +16,7 @@ module Sidekiq # We need to go through the list one at a time to reduce the risk of something # going wrong between the time jobs are popped from the scheduled queue and when # they are pushed onto a work queue and losing the jobs. - while job = conn.zrangebyscore(sorted_set, '-inf', now, :limit => [0, 1]).first do + while job = conn.zrangebyscore(sorted_set, '-inf'.freeze, now, :limit => [0, 1]).first do # Pop item off the queue and add it to the work queue. If the job can't be popped from # the queue, it's because another process already popped it so we can move on to the