Skip to content

Commit

Permalink
WHISTLE-1441: handle sending the member_connect_retry better
Browse files Browse the repository at this point in the history
  • Loading branch information
James Aimonetti committed Sep 19, 2012
1 parent 249c5c9 commit 9fbc350
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions whistle_apps/apps/acdc/src/acdc_agent.erl
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,24 @@ init([Supervisor, AgentJObj, Queues]) ->
gen_listener:cast(self(), {load_endpoints, Supervisor}),

Self = self(),
AcctId = wh_json:get_value(<<"pvt_account_id">>, AgentJObj),

_ = spawn(fun() ->
gen_listener:cast(Self, {queue_name, gen_listener:queue_name(Self)})
put(amqp_publish_as, Self),
gen_listener:cast(Self, {queue_name, gen_listener:queue_name(Self)}),
Prop = [{<<"Account-ID">>, AcctId}
,{<<"Agent-ID">>, AgentId}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
],
[wapi_acdc_queue:publish_agent_available([{<<"Queue-ID">>, QueueId} | Prop]) || QueueId <- Queues]
end),

{ok, #state{
agent_id = AgentId
,acct_id = wh_json:get_value(<<"pvt_account_id">>, AgentJObj)
,acct_id = AcctId
,acct_db = wh_json:get_value(<<"pvt_account_db">>, AgentJObj)
,agent_queues = Queues
,my_id = acdc_util:agent_proc_id(self())
,my_id = acdc_util:proc_id()
,supervisor = Supervisor
}}.

Expand Down Expand Up @@ -358,34 +366,35 @@ handle_cast({member_connect_resp, ReqJObj}, #state{
,my_id=MyId
,my_q=MyQ
}=State) ->
lager:debug("responding to member_connect_req"),

ACDcQueue = wh_json:get_value(<<"Queue-ID">>, ReqJObj),
case is_valid_queue(ACDcQueue, Qs) of
false -> {noreply, State};
false ->
lager:debug("Queue ~s isn't one of ours", [ACDcQueue]),
{noreply, State};
true ->
lager:debug("responding to member_connect_req"),

send_member_connect_resp(ReqJObj, MyQ, AgentId, MyId, LastConn),
{noreply, State#state{acdc_queue_id = ACDcQueue
,msg_queue_id = wh_json:get_value(<<"Server-ID">>, ReqJObj)
}}
end;

handle_cast({member_connect_retry, CallId}, #state{
my_id=MyId
,msg_queue_id=Server
}=State) when is_binary(CallId) ->
handle_cast({member_connect_retry, CallId}, #state{my_id=MyId
,msg_queue_id=Server
}=State) when is_binary(CallId) ->
send_member_connect_retry(Server, CallId, MyId),
{noreply, State#state{msg_queue_id=undefined
,acdc_queue_id=undefined
}};
handle_cast({member_connect_retry, WinJObj}, #state{
my_id=MyId
}=State) ->
lager:debug("cannot process this call, sending a retry"),
handle_cast({member_connect_retry, WinJObj}, #state{my_id=MyId}=State) ->
lager:debug("cannot process this call, sending a retry: ~p", [WinJObj]),
send_member_connect_retry(WinJObj, MyId),
{noreply, State};

handle_cast({bridge_to_member, WinJObj}, #state{endpoints=EPs, fsm_pid=FSM}=State) ->
handle_cast({bridge_to_member, WinJObj}, #state{endpoints=EPs
,fsm_pid=FSM
}=State) ->
lager:debug("bridging to agent endpoints: ~p", [EPs]),

Call = whapps_call:from_json(wh_json:get_value(<<"Call">>, WinJObj)),
Expand Down Expand Up @@ -518,6 +527,7 @@ send_member_connect_resp(JObj, MyQ, AgentId, MyId, LastConn) ->
,{<<"Process-ID">>, MyId}
| wh_api:default_headers(MyQ, ?APP_NAME, ?APP_VERSION)
]),
lager:debug("sending connect_resp to ~s: ~p", [Queue, Resp]),
wapi_acdc_queue:publish_member_connect_resp(Queue, Resp).

-spec send_member_connect_retry/2 :: (wh_json:json_object(), ne_binary()) -> 'ok'.
Expand Down

0 comments on commit 9fbc350

Please sign in to comment.