Permalink
Browse files

WHISTLE-1441: fix query and api params

WHISTLE-1441: stop super, listener, and fsm as appropriate

WHISTLE-1441: fetch the call-id using a variety of keys in the json object

WHISTLE-1441: set missing values when monitoring, and call the right elapsed/1; fix reg query payload;

WHISTLE-1441: fix query and api params
  • Loading branch information...
James Aimonetti
James Aimonetti committed Oct 11, 2012
1 parent 1f17cee commit 61144843ad05d41888aeaac889ed093201df2082
@@ -270,7 +270,7 @@ handle_call(_Request, _From, State) ->
%% @end
%%--------------------------------------------------------------------
handle_cast({stop_agent}, #state{supervisor=Supervisor}=State) ->
- acdc_agent_sup:stop(Supervisor),
+ _ = acdc_agent_sup:stop(Supervisor),
{noreply, State};
handle_cast({start_fsm, Supervisor}, #state{acct_id=AcctId
,agent_id=AgentId
@@ -504,7 +504,7 @@ handle_event(_JObj, #state{fsm_pid=FSM}) ->
%% @end
%%--------------------------------------------------------------------
terminate(_Reason, #state{supervisor=Supervisor}) ->
- acdc_agent_sup:stop(Supervisor),
+ _ = acdc_agent_sup:stop(Supervisor),
lager:debug("agent process going down: ~p", [_Reason]).
%%--------------------------------------------------------------------
@@ -607,21 +607,24 @@ idle_time(undefined) -> undefined;
idle_time(T) -> wh_util:elapsed_s(T).
-spec call_id/1 :: ('undefined' | whapps_call:call() | wh_json:json_object()) ->
- 'undefined' | ne_binary().
--spec call_id/2 :: (whapps_call:call() | wh_json:json_object(), 'undefined' | whapps_call:call()) ->
- 'undefined' | ne_binary().
+ api_binary().
call_id(undefined) -> undefined;
call_id(Call) ->
case whapps_call:is_call(Call) of
true -> whapps_call:call_id(Call);
false ->
- call_id(Call, wh_json:get_value([<<"Call">>, <<"call_id">>], Call))
+ Keys = [[<<"Call">>, <<"Call-ID">>]
+ ,[<<"Call">>, <<"call_id">>]
+ ,<<"Call-ID">>
+ ],
+ lists:foldl(fun(K, undefined) -> wh_json:get_value(K, Call);
+ (_, CallId) -> CallId
+ end
+ ,undefined
+ ,Keys
+ )
end.
-call_id(Call, undefined) ->
- wh_json:get_value([<<"Call-ID">>], Call);
-call_id(_, CallId) -> CallId.
-
-spec maybe_connect_to_agent/4 :: (pid(), list(), whapps_call:call(), integer() | 'undefined') -> 'ok'.
maybe_connect_to_agent(FSM, EPs, Call, Timeout) ->
put(callid, whapps_call:call_id(Call)),
@@ -377,6 +377,8 @@ ready({member_connect_monitor, JObj}, #state{agent_proc=Srv}=State) ->
{next_state, ringing, State#state{wrapup_timeout=WrapupTimer
,member_call_id=CallId
+ ,member_call_start=erlang:now()
+ ,member_call_queue_id=wh_json:get_value(<<"Queue-ID">>, JObj)
}};
ready({member_connect_req, JObj}, #state{agent_proc=Srv}=State) ->
@@ -438,36 +440,33 @@ ringing({originate_failed, timeout}, #state{agent_proc=Srv
acdc_stats:call_missed(AcctId, QueueId, AgentId, CallId),
{next_state, ready, clear_call(State)};
-ringing({originate_failed, JObj}
- ,#state{agent_proc=Srv
- ,acct_id=AcctId
- ,agent_id=AgentId
- ,member_call_queue_id=QueueId
- ,member_call_id=CallId
- }=State) ->
+ringing({originate_failed, JObj}, #state{agent_proc=Srv
+ ,acct_id=AcctId
+ ,agent_id=AgentId
+ ,member_call_queue_id=QueueId
+ ,member_call_id=CallId
+ }=State) ->
lager:debug("failed to prepare originate to the agent: ~p", [JObj]),
acdc_agent:member_connect_retry(Srv, JObj),
acdc_stats:call_missed(AcctId, QueueId, AgentId, CallId),
{next_state, ready, clear_call(State)};
-ringing({channel_bridged, CallId}
- ,#state{agent_proc=Srv
- ,member_call_id=CallId
- }=State) ->
+ringing({channel_bridged, CallId}, #state{agent_proc=Srv
+ ,member_call_id=CallId
+ }=State) ->
lager:debug("agent has connected to member"),
acdc_agent:member_connect_accepted(Srv),
{next_state, answered, State};
-ringing({channel_hungup, CallId}
- ,#state{agent_proc=Srv
- ,agent_call_id=CallId
- ,acct_id=AcctId
- ,agent_id=AgentId
- ,member_call_queue_id=QueueId
- ,member_call_id=MCallId
- }=State) ->
+ringing({channel_hungup, CallId}, #state{agent_proc=Srv
+ ,agent_call_id=CallId
+ ,acct_id=AcctId
+ ,agent_id=AgentId
+ ,member_call_queue_id=QueueId
+ ,member_call_id=MCallId
+ }=State) ->
lager:debug("agent channel was destroyed before we could connect: ~s", [CallId]),
acdc_agent:channel_hungup(Srv, CallId),
@@ -476,13 +475,12 @@ ringing({channel_hungup, CallId}
{next_state, ready, clear_call(State)};
-ringing({channel_hungup, CallId}
- ,#state{agent_proc=Srv
- ,member_call_id=CallId
- ,acct_id=AcctId
- ,member_call_queue_id=QueueId
- ,agent_call_id=AgentCallId
- }=State
+ringing({channel_hungup, CallId}, #state{agent_proc=Srv
+ ,acct_id=AcctId
+ ,member_call_id=CallId
+ ,member_call_queue_id=QueueId
+ ,agent_call_id=AgentCallId
+ }=State
) ->
lager:debug("member channel (~s) has gone down, stop agent call", [CallId]),
acdc_agent:channel_hungup(Srv, AgentCallId),
@@ -560,7 +558,7 @@ answered({channel_hungup, CallId}
lager:debug("agent call has hungup, going into a wrapup period ~p: ~s", [WrapupTimeout, CallId]),
acdc_stats:call_processed(AcctId, QueueId, AgentId
- ,MCallId, wh_util:elapsed_s(Started)
+ ,MCallId, elapsed(Started)
),
acdc_agent:channel_hungup(Srv, CallId),
@@ -583,7 +581,7 @@ answered({channel_hungup, CallId}
lager:debug("member call has hungup, going into a wrapup period ~p: ~s", [WrapupTimeout, CallId]),
acdc_stats:call_processed(AcctId, QueueId, AgentId
- ,CallId, wh_util:elapsed_s(Started)
+ ,CallId, elapsed(Started)
),
acdc_agent:channel_hungup(Srv, CallId),
@@ -61,13 +61,14 @@ is_endpoint_registered(EPDoc, AcctRealm) ->
Query = [{<<"Realm">>, AcctRealm}
,{<<"Username">>, wh_json:get_value([<<"sip">>, <<"username">>], EPDoc)}
,{<<"Fields">>, [<<"Contact">>]}
+ | wh_api:default_headers(?APP_NAME, ?APP_VERSION)
],
case whapps_util:amqp_pool_request(Query
,fun wapi_registration:publish_query_req/1
,fun wapi_registration:query_resp_v/1
) of
{ok, _Resp} -> true;
- {error, _E} -> false
+ {error, _E} -> lager:debug("reg query failed: ~p", [_E]), false
end.
-spec get_endpoint/2 :: (whapps_call:call(), ne_binary()) -> wh_json:json_object() | 'undefined'.
@@ -91,13 +91,20 @@ sync_req_routing_key(AcctId, Id) ->
-define(OPTIONAL_SYNC_RESP_HEADERS, [<<"Call-ID">>, <<"Time-Left">>, <<"Process-ID">>]).
-define(SYNC_RESP_VALUES, [{<<"Event-Category">>, <<"agent">>}
,{<<"Event-Name">>, <<"sync_resp">>}
- ,{<<"Status">>, [<<"init">>, <<"ready">>, <<"waiting">>, <<"ringing">>
- ,<<"answered">>, <<"wrapup">>, <<"paused">>
+ ,{<<"Status">>, [<<"init">>
+ ,<<"sync">>
+ ,<<"ready">>
+ ,<<"waiting">>
+ ,<<"ringing">>
+ ,<<"answered">>
+ ,<<"wrapup">>
+ ,<<"paused">>
]}
- ]).
+ ]).
-define(SYNC_RESP_TYPES, []).
--spec sync_resp/1 :: (api_terms()) -> {'ok', iolist()} | {'error', string()}.
+-spec sync_resp/1 :: (api_terms()) -> {'ok', iolist()} |
+ {'error', string()}.
sync_resp(Props) when is_list(Props) ->
case sync_resp_v(Props) of
true -> wh_api:build_message(Props, ?SYNC_RESP_HEADERS, ?OPTIONAL_SYNC_RESP_HEADERS);
@@ -128,7 +135,8 @@ sync_resp_v(JObj) ->
]).
-define(STATS_REQ_TYPES, []).
--spec stats_req/1 :: (api_terms()) -> {'ok', iolist()} | {'error', string()}.
+-spec stats_req/1 :: (api_terms()) -> {'ok', iolist()} |
+ {'error', string()}.
stats_req(Props) when is_list(Props) ->
case stats_req_v(Props) of
true -> wh_api:build_message(Props, ?STATS_REQ_HEADERS, ?OPTIONAL_STATS_REQ_HEADERS);

0 comments on commit 6114484

Please sign in to comment.