From 10dc6f6664af25520924c8cb2a5af0ee8cb16fe8 Mon Sep 17 00:00:00 2001 From: Daniel Alkalai Date: Wed, 2 Apr 2014 17:18:24 -0700 Subject: [PATCH 1/3] Modifying priority queue creation to place a job with a priority that is not found in Sidekiq::Priority.priorities in the default queue, rather than creating a new one. --- lib/sidekiq/priority.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sidekiq/priority.rb b/lib/sidekiq/priority.rb index 0eaeec4..6d6093f 100644 --- a/lib/sidekiq/priority.rb +++ b/lib/sidekiq/priority.rb @@ -18,7 +18,7 @@ def self.priorities=(priorities) end def self.queue_with_priority(queue, priority) - priority.nil? ? queue : "#{queue}_#{priority}" + priority && self.priorities.indlude?(priority) ? "#{queue}_#{priority}" : queue end end end From 2c551196312fcb08feaa2070f0798b81ce8d5101 Mon Sep 17 00:00:00 2001 From: Daniel Alkalai Date: Thu, 3 Apr 2014 09:05:27 -0700 Subject: [PATCH 2/3] Fixed typo --- lib/sidekiq/priority.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sidekiq/priority.rb b/lib/sidekiq/priority.rb index 6d6093f..c901adb 100644 --- a/lib/sidekiq/priority.rb +++ b/lib/sidekiq/priority.rb @@ -18,7 +18,7 @@ def self.priorities=(priorities) end def self.queue_with_priority(queue, priority) - priority && self.priorities.indlude?(priority) ? "#{queue}_#{priority}" : queue + priority && self.priorities.include?(priority) ? "#{queue}_#{priority}" : queue end end end From 000b697cb36f0fb658a8029f5757274c2126aef9 Mon Sep 17 00:00:00 2001 From: Daniel Alkalai Date: Thu, 3 Apr 2014 17:31:05 -0700 Subject: [PATCH 3/3] Added spec to test giving a nil priority and to test giving a priority that is not in Sidekiq::Priority.priorities --- spec/sidekiq/worker_ext_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/sidekiq/worker_ext_spec.rb b/spec/sidekiq/worker_ext_spec.rb index cfe9895..f98e27c 100644 --- a/spec/sidekiq/worker_ext_spec.rb +++ b/spec/sidekiq/worker_ext_spec.rb @@ -22,5 +22,26 @@ def perform(first, second) 'queue' => 'foo_high' } end + + it 'sends an item to the default queue if priority is nil' do + TestWorker.stub(:client_push) { |item| item } + item = TestWorker.perform_with_priority(:invalid_priority, 1, 2) + item.should == { + 'class' => TestWorker, + 'args' => [1, 2], + 'queue' => :foo + } + end + + it 'sends an item to the default queue if a random priority is given' do + TestWorker.stub(:client_push) { |item| item } + item = TestWorker.perform_with_priority(:random_priority, 1, 2) + item.should == { + 'class' => TestWorker, + 'args' => [1, 2], + 'queue' => :foo + } + end + end end