Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A worker wasn't getting the default queue name setting. I fixed it an…

…d added tests.
  • Loading branch information...
commit 43b0279ace59fcad21bb61c6a00626c73ecbd8e0 1 parent 66b3962
@bracken bracken authored
Showing with 24 additions and 5 deletions.
  1. +2 −2 lib/delayed/worker.rb
  2. +22 −3 spec/worker_spec.rb
View
4 lib/delayed/worker.rb
@@ -20,7 +20,7 @@ class Worker
end
# name_prefix is ignored if name is set directly
- attr_accessor :name_prefix
+ attr_accessor :name_prefix, :queue
cattr_reader :backend
@@ -35,7 +35,7 @@ def self.backend=(backend)
def initialize(options={})
@quiet = options[:quiet]
- @queue = options[:queue]
+ @queue = options[:queue] || self.class.queue
self.class.min_priority = options[:min_priority] if options.has_key?(:min_priority)
self.class.max_priority = options[:max_priority] if options.has_key?(:max_priority)
end
View
25 spec/worker_spec.rb
@@ -178,8 +178,9 @@ def worker_create(opts = {})
end
- context "Different queue workers" do
+ context "Queue workers" do
before :each do
+ Delayed::Worker.queue = nil
job_create(:queue => 'queue1')
job_create(:queue => 'queue2')
job_create(:queue => nil)
@@ -207,12 +208,30 @@ def worker_create(opts = {})
SimpleJob.runs.should == 0
end
- it "should run non-named runner jobs when the runner has no name set" do
+ it "should run non-named queue jobs when the queue has no name set" do
worker = worker_create(:queue=>nil)
-
SimpleJob.runs.should == 0
worker.work_off
SimpleJob.runs.should == 1
end
+
+ it "should get the default queue if none is set" do
+ queue_name = "default_queue"
+ Delayed::Worker.queue = queue_name
+ worker = worker_create(:queue=>nil)
+ worker.queue.should == queue_name
+ end
+
+ it "should override default queue name if specified in initialize" do
+ queue_name = "my_queue"
+ Delayed::Worker.queue = "default_queue"
+ worker = worker_create(:queue=>queue_name)
+ worker.queue.should == queue_name
+ end
+
+ it "shouldn't have a queue if none is set" do
+ worker = worker_create(:queue=>nil)
+ worker.queue.should == nil
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.