From 39b2094ca9e1b4124a5446bb85f1a310080c0511 Mon Sep 17 00:00:00 2001 From: Lloyd Hughes Date: Tue, 1 Nov 2016 08:28:28 +0100 Subject: [PATCH 1/3] Fixed nil calls in queue causing agents to become stranded when using :manual return mode --- CHANGELOG.md | 1 + lib/electric_slide/call_queue.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78d634a..473489b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # [develop](https://github.com/adhearsion/electric_slide) + * Bugfix: Prevent nil objects in the call queue from crashing on connection * Added `ElectricSlide::CallQueue#update_agent` to safely update a queued agent object's attributes * Added `ElectricSlide::Agent#update` to update an agent object's attributes * Added `ElectricSlide::Agent#callable?` to check if an agent can be called diff --git a/lib/electric_slide/call_queue.rb b/lib/electric_slide/call_queue.rb index 6c570d6..c26ba7c 100644 --- a/lib/electric_slide/call_queue.rb +++ b/lib/electric_slide/call_queue.rb @@ -241,6 +241,8 @@ def remove_agent(agent, extra_params = {}) # Checks to see if any callers are waiting for an agent and attempts to connect them to # an available agent def check_for_connections + # Ensure there are no nil objects in the call queue before trying to connect + @queue.compact! connect checkout_agent, get_next_caller while call_waiting? && agent_available? end @@ -290,6 +292,8 @@ def remove_call(call) def connect(agent, queued_call) unless queued_call && queued_call.active? logger.warn "Inactive queued call found in #connect" + agent.callback :connection_failed, current_actor, agent.call, queued_call + return_agent agent return end From 89db80912c074ea410b68c7bf7ad9ae2a3aadf45 Mon Sep 17 00:00:00 2001 From: Lloyd Hughes Date: Wed, 16 Nov 2016 13:12:46 +0100 Subject: [PATCH 2/3] Connect callback is trigered before the call is actually connected --- lib/electric_slide/call_queue.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/electric_slide/call_queue.rb b/lib/electric_slide/call_queue.rb index c26ba7c..21e6100 100644 --- a/lib/electric_slide/call_queue.rb +++ b/lib/electric_slide/call_queue.rb @@ -451,11 +451,11 @@ def bridge_agent(agent, queued_call) end queued_call.register_tmp_handler :event, Punchblock::Event::Joined do |event| + agent.callback :connect, current_actor, agent.call, queued_call + queued_call[:electric_slide_connected_at] = event.timestamp end - agent.callback :connect, current_actor, agent.call, queued_call - agent.join queued_call if queued_call.active? rescue *ENDED_CALL_EXCEPTIONS ignoring_ended_calls do From 7acad819f9250973f7b448e19bc8d350044a759a Mon Sep 17 00:00:00 2001 From: Lloyd Hughes Date: Thu, 17 Nov 2016 13:14:59 +0100 Subject: [PATCH 3/3] Moved notification out of handler --- lib/electric_slide/call_queue.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/electric_slide/call_queue.rb b/lib/electric_slide/call_queue.rb index 21e6100..3952fd3 100644 --- a/lib/electric_slide/call_queue.rb +++ b/lib/electric_slide/call_queue.rb @@ -450,13 +450,13 @@ def bridge_agent(agent, queued_call) agent.call[:queued_call] = nil if agent.call end - queued_call.register_tmp_handler :event, Punchblock::Event::Joined do |event| - agent.callback :connect, current_actor, agent.call, queued_call - + queued_call.register_tmp_handler :event, Punchblock::Event::Joined do |event| queued_call[:electric_slide_connected_at] = event.timestamp end agent.join queued_call if queued_call.active? + agent.callback :connect, current_actor, agent.call, queued_call + rescue *ENDED_CALL_EXCEPTIONS ignoring_ended_calls do if agent.call && agent.call.active?