Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a .queue_name method to CallQueue... #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Example Queue

```Ruby
class SupportQueue < ElectricSlide::Queue
name "Support Queue"
queue_name "Support Queue"

caller_strategy :fifo
agent_strategy :fifo
Expand Down
5 changes: 3 additions & 2 deletions lib/electric_slide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion lib/electric_slide/call_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
47 changes: 32 additions & 15 deletions spec/electric_slide/call_queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions spec/electric_slide_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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