Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Dec 17, 2015
2 parents 7f26040 + 722853e commit a38d260
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .lgtm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
approvals = 1
pattern = "(?i):shipit:|:\\+1:|LGTM"
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# [develop](https://github.com/adhearsion/electric_slide)

# [0.4.0](https://github.com/adhearsion/electric_slide/compare/v0.3.0...v0.4.0) - [2015-12-17](https://rubygems.org/gems/adhearsion/versions/0.4.0)
* Change `ElectricSlide::Agent` `#presence=` method name to `#update_presence`. It will also accept one more parameter called `extra_params`, a hash that holds application specific parameters that are passed to the presence change callback.
* `ElectricSlide::CallQueue#add_agent` will no longer wait for a connection attempt to complete before returning

# [0.3.0](https://github.com/adhearsion/electric_slide/compare/v0.2.0...v0.3.0) - [2015-12-01](https://rubygems.org/gems/adhearsion/versions/0.3.0)
* Trigger an agent "presence change" callback when the agent is removed from the queue
* Bugfix: Fix `NameError` exception when referencing namespaced constant `Adhearsion::Call::ExpiredError` in injected `Adhearsion::Call#active?` method
* Provide Electric Slide with a way to check if a queue with a given set of attributes is valid/can be instantiated before Electric Slide adds it to the supervision group. The supervisor will crash if its attempt to create the queue raises an exception.
Expand Down
2 changes: 2 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ben Langfeld <[email protected]> (@benlangfeld)
Ben Klang <[email protected]> (@bklang)
7 changes: 4 additions & 3 deletions lib/electric_slide/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

class ElectricSlide
class Agent
attr_accessor :id, :address, :presence, :call, :queue
attr_accessor :id, :address, :call, :queue
attr_reader :presence

# @param [Hash] opts Agent parameters
# @option opts [String] :id The Agent's ID
Expand All @@ -14,10 +15,10 @@ def initialize(opts = {})
@presence = opts[:presence] || :available
end

def presence=(new_presence)
def update_presence(new_presence, extra_params = {})
old_presence = @presence
@presence = new_presence
callback :presence_change, queue, @call, new_presence, old_presence
callback :presence_change, queue, @call, new_presence, old_presence, extra_params
end

def callback(type, *args)
Expand Down
11 changes: 6 additions & 5 deletions lib/electric_slide/call_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def available_agent_summary
def checkout_agent
agent = @strategy.checkout_agent
if agent
agent.presence = :on_call
agent.update_presence(:on_call)
end
agent
end
Expand Down Expand Up @@ -179,7 +179,7 @@ def add_agent(agent)
# Fake the presence callback since this is a new agent
agent.callback :presence_change, self, agent.call, agent.presence, :unavailable

check_for_connections
async.check_for_connections
end

# Marks an agent as available to take a call. To be called after an agent completes a call
Expand All @@ -192,7 +192,7 @@ def return_agent(agent, new_presence = :available, address = nil)

return false unless get_agent(agent.id)

agent.presence = new_presence
agent.update_presence(new_presence)
agent.address = address if address

case agent.presence
Expand All @@ -216,9 +216,10 @@ def return_agent!(*args)

# Removes an agent from the queue entirely
# @param [Agent] agent The {Agent} to be removed from the queue
# @param [Hash] extra_params Application specific extra params
# @return [Agent, Nil] The Agent object if removed, Nil otherwise
def remove_agent(agent)
agent.presence = :unavailable
def remove_agent(agent, extra_params = {})
agent.update_presence(:unavailable, extra_params)
@strategy.delete agent
@agents.delete agent
logger.info "Removing agent #{agent} from the queue"
Expand Down
2 changes: 1 addition & 1 deletion lib/electric_slide/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8
class ElectricSlide
VERSION = '0.3.0'
VERSION = '0.4.0'
end
19 changes: 18 additions & 1 deletion spec/electric_slide/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ def foo
called = false
ElectricSlide::Agent.on_presence_change { |queue, agent_call, presence| called = true }
agent = ElectricSlide::Agent.new presence: :unavailable
agent.presence = :busy
agent.update_presence(:busy)

expect(called).to be_truthy
end

it 'sends `extra_params` and `old_presence` to the presence change callback' do
presence_change_attributes = []
ElectricSlide::Agent.on_presence_change do |*attrs|
presence_change_attributes = attrs
end

agent = ElectricSlide::Agent.new presence: :unavailable
agent.update_presence(:busy, triggered_by: 'auto')

queue, agent_call, presence, old_presence, extra_params = presence_change_attributes

expect(old_presence).to eq :unavailable
expect(extra_params[:triggered_by]).to eq 'auto'
end
end
14 changes: 11 additions & 3 deletions spec/electric_slide/call_queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
# prevent the agent from being returned to the queue so the queued
# call isn't grabbed by the agent again, changing queued call state
# before the example can check it
agent.presence = :unavailable
agent.update_presence(:unavailable)
end

it 'unsets the `:agent` call variable on the queued call' do
Expand Down Expand Up @@ -264,7 +264,15 @@
}.to change(queue, :checkout_agent).from(nil).to(agent)
end

it "connects the agent to waiting queued calls"
it "connects the agent to waiting queued calls" do
call = Adhearsion::OutboundCall.new
queue.enqueue call

queue.add_agent agent
sleep 0.5
expect(agent.presence).to eq(:on_call)
expect(call[:agent]).to eq(agent)
end

context 'when given an agent already in the queue' do
before do
Expand Down Expand Up @@ -352,7 +360,7 @@
called = false
ElectricSlide::Agent.on_presence_change { |queue, agent_call, presence| called = true }
queue.remove_agent agent
expect(called).to be
expect(called).to be_truthy
end

it 'takes the agent out of the call rotation' do
Expand Down

0 comments on commit a38d260

Please sign in to comment.