diff --git a/README.markdown b/README.markdown index d83fae2..a358c50 100644 --- a/README.markdown +++ b/README.markdown @@ -22,7 +22,7 @@ Example Queue ```Ruby class SupportQueue < ElectricSlide::Queue - name "Support Queue" + queue_name "Support Queue" caller_strategy :fifo agent_strategy :fifo diff --git a/lib/electric_slide.rb b/lib/electric_slide.rb index a61efed..615bad8 100644 --- a/lib/electric_slide.rb +++ b/lib/electric_slide.rb @@ -26,8 +26,9 @@ def create(name, queue_class = nil, *args) end def get_queue(name) - fail "Queue #{name} not found!" unless @queues.key?(name) - @queues[name] + queue = Celluloid::Actor[name] || @queues[name] + fail "Queue #{name} not found!" unless queue + queue end def shutdown_queue(name) diff --git a/lib/electric_slide/call_queue.rb b/lib/electric_slide/call_queue.rb index 4aa31b9..5370fb9 100644 --- a/lib/electric_slide/call_queue.rb +++ b/lib/electric_slide/call_queue.rb @@ -3,6 +3,12 @@ class ElectricSlide class CallQueue include Celluloid + @queue_name = 'call queue' + + def self.queue_name(queue_name) + @queue_name = queue_name + end + def initialize @free_agents = [] # Needed to keep track of waiting order @agents = [] # Needed to keep track of global list of agents @@ -162,7 +168,8 @@ def calls_waiting end def self.work - self.supervise + self.supervise_as @queue_name + Celluloid::Actor[@queue_name] end end end diff --git a/spec/electric_slide/call_queue_spec.rb b/spec/electric_slide/call_queue_spec.rb index 13df11e..cf7275f 100644 --- a/spec/electric_slide/call_queue_spec.rb +++ b/spec/electric_slide/call_queue_spec.rb @@ -6,25 +6,42 @@ let(:call_a) { dummy_call } let(:call_b) { dummy_call } let(:call_c) { dummy_call } - before :each do - queue.enqueue call_a - queue.enqueue call_b - queue.enqueue call_c - end - it "should return callers in the same order they were enqueued" do - expect(queue.get_next_caller).to be call_a - expect(queue.get_next_caller).to be call_b - expect(queue.get_next_caller).to be call_c + describe ".queue_name" do + it "works as a supervised actor with a name" do + expect(ElectricSlide::CallQueue.work).to eq Celluloid::Actor['call queue'] + end + + context "when given a different name" do + after { ElectricSlide::CallQueue.queue_name 'call queue' } + + it "works as a different actor if given a different name" do + ElectricSlide::CallQueue.queue_name :other_queue + expect(ElectricSlide::CallQueue.work).to eq Celluloid::Actor[:other_queue] + end + end end - it "should return a priority caller ahead of the queue" do - call_d = dummy_call - queue.priority_enqueue call_d - expect(queue.get_next_caller).to be call_d - expect(queue.get_next_caller).to be call_a + describe "#.enqueue" do + before :each do + queue.enqueue call_a + queue.enqueue call_b + queue.enqueue call_c + end + + it "should return callers in the same order they were enqueued" do + expect(queue.get_next_caller).to be call_a + expect(queue.get_next_caller).to be call_b + expect(queue.get_next_caller).to be call_c + end + + it "should return a priority caller ahead of the queue" do + call_d = dummy_call + queue.priority_enqueue call_d + expect(queue.get_next_caller).to be call_d + expect(queue.get_next_caller).to be call_a + end end it "should select the agent that has been waiting the longest" - end diff --git a/spec/electric_slide_spec.rb b/spec/electric_slide_spec.rb index 5924657..d6418cf 100644 --- a/spec/electric_slide_spec.rb +++ b/spec/electric_slide_spec.rb @@ -38,4 +38,9 @@ expect { ElectricSlide.shutdown_queue("does not exist!") }.to raise_error end + it "gets the celluloid named queue before searching the queues array" do + ElectricSlide.create :foo + expect(Celluloid::Actor).to receive(:[]).with(:foo).and_return :celluloid_queue + expect(ElectricSlide.get_queue :foo).to eq :celluloid_queue + end end