Skip to content

Commit

Permalink
[4.3] Many dialyzer fixes for acdc (2600hz#6590)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfinke authored and jamesaimonetti committed Jun 18, 2020
1 parent dcfed9f commit 542e518
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 41 deletions.
12 changes: 5 additions & 7 deletions applications/acdc/src/acdc.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

-define(CACHE_NAME, 'acdc_cache').

-define(ABANDON_TIMEOUT, 'member_timeout').
-define(ABANDON_EXIT, 'member_exit').
-define(ABANDON_HANGUP, 'member_hangup').
-define(ABANDON_EMPTY, 'member_exit_empty').
-define(ABANDON_TIMEOUT, <<"member_timeout">>).
-define(ABANDON_EXIT, <<"member_exit">>).
-define(ABANDON_HANGUP, <<"member_hangup">>).
-define(ABANDON_EMPTY, <<"member_exit_empty">>).
-define(ABANDON_INTERNAL_ERROR, <<"INTERNAL ERROR">>).

-define(PRESENCE_GREEN, <<"terminated">>).
-define(PRESENCE_RED_FLASH, <<"early">>).
Expand All @@ -34,9 +35,6 @@
-define(DESTROYED_CHANNEL_REG(AcctId, User), {'p', 'l', {'destroyed_channel', AcctId, User}}).
-define(DESTROYED_CHANNEL(CallId, HangupCause), {'call_down', CallId, HangupCause}).

-type abandon_reason() :: ?ABANDON_TIMEOUT | ?ABANDON_EXIT |
?ABANDON_HANGUP.

-type deliveries() :: [gen_listener:basic_deliver()].

-type announcements_pids() :: #{kz_term:ne_binary() => pid()}.
Expand Down
15 changes: 8 additions & 7 deletions applications/acdc/src/acdc_agent_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ call_id(JObj) ->
end.

%% returns time left in seconds
-spec time_left(reference() | 'false' | kz_term:api_integer()) -> kz_term:api_integer().
-spec time_left(kz_term:api_reference() | 'false' | timeout()) -> timeout() | 'undefined'.
time_left(Ref) when is_reference(Ref) ->
time_left(erlang:read_timer(Ref));
time_left('false') -> 'undefined';
Expand Down Expand Up @@ -1783,7 +1783,7 @@ convert_to_endpoint(EPDoc) ->
],

Call = kapps_call:exec(Setters, kapps_call:new()),
case kz_endpoint:build(kz_doc:id(EPDoc), [], Call) of
case kz_endpoint:build(kz_doc:id(EPDoc), kz_json:new(), Call) of
{'ok', EP} -> EP;
{'error', _} -> 'undefined'
end.
Expand Down Expand Up @@ -1899,7 +1899,7 @@ notify(Url, 'get', Data) ->
,[], 'get', <<>>, []
).

-spec notify(iolist(), kz_term:proplist(), 'get' | 'post', binary(), kz_term:proplist()) -> 'ok'.
-spec notify(kz_term:ne_binary(), kz_term:proplist(), 'get' | 'post', binary(), kz_term:proplist()) -> 'ok'.
notify(Uri, Headers, Method, Body, Opts) ->
Options = [{'connect_timeout', 200}
,{'timeout', 1000}
Expand Down Expand Up @@ -1927,13 +1927,14 @@ recording_url(JObj) ->
Url -> Url
end.

-spec uri(kz_term:ne_binary(), iolist()) -> iolist().
-spec uri(kz_term:ne_binary(), iolist()) -> kz_term:ne_binary().
uri(URI, QueryString) ->
QueryBinary = kz_term:to_binary(QueryString),
case kz_http_util:urlsplit(URI) of
{Scheme, Host, Path, <<>>, Fragment} ->
kz_http_util:urlunsplit({Scheme, Host, Path, QueryString, Fragment});
kz_http_util:urlunsplit({Scheme, Host, Path, QueryBinary, Fragment});
{Scheme, Host, Path, QS, Fragment} ->
kz_http_util:urlunsplit({Scheme, Host, Path, <<QS/binary, "&", (kz_term:to_binary(QueryString))/binary>>, Fragment})
kz_http_util:urlunsplit({Scheme, Host, Path, <<QS/binary, "&", QueryBinary/binary>>, Fragment})
end.

-spec apply_state_updates(state()) -> kz_types:handle_fsm_ret(state()).
Expand Down Expand Up @@ -2021,7 +2022,7 @@ handle_resume(#state{agent_listener=AgentListener
acdc_agent_listener:presence_update(AgentListener, ?PRESENCE_GREEN),
{'next_state', 'ready', State#state{pause_ref='undefined'}}.

-spec handle_pause(integer(), state()) -> kz_types:handle_fsm_ret(state()).
-spec handle_pause(timeout(), state()) -> kz_types:handle_fsm_ret(state()).
handle_pause(Timeout, #state{agent_listener=AgentListener}=State) ->
acdc_agent_listener:presence_update(AgentListener, ?PRESENCE_RED_FLASH),
Ref = start_pause_timer(Timeout),
Expand Down
25 changes: 13 additions & 12 deletions applications/acdc/src/acdc_agent_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
,msg_queue_id :: kz_term:api_ne_binary() % the AMQP Queue ID of the ACDc Queue process
,agent_id :: kz_term:api_ne_binary()
,acct_db :: kz_term:api_ne_binary()
,acct_id :: kz_term:api_ne_binary()
,acct_id :: kz_term:api_binary()
,fsm_pid :: kz_term:api_pid()
,agent_queues = [] :: kz_term:ne_binaries()
,last_connect :: kz_time:now() | 'undefined' % last connection
Expand Down Expand Up @@ -1203,28 +1203,28 @@ recording_format() ->

-spec agent_id(agent()) -> kz_term:api_binary().
agent_id(Agent) ->
case kz_json:is_json_object(Agent) of
'true' -> kz_doc:id(Agent);
'false' -> kapps_call:owner_id(Agent)
case is_thief(Agent) of
'true' -> kapps_call:owner_id(Agent);
'false' -> kz_doc:id(Agent)
end.

-spec account_id(agent()) -> kz_term:api_binary().
account_id(Agent) ->
case kz_json:is_json_object(Agent) of
'true' -> find_account_id(Agent);
'false' -> kapps_call:account_id(Agent)
case is_thief(Agent) of
'true' -> kapps_call:account_id(Agent);
'false' -> find_account_id(Agent)
end.

-spec account_db(agent()) -> kz_term:api_binary().
-spec account_db(agent()) -> kz_term:api_ne_binary().
account_db(Agent) ->
case kz_json:is_json_object(Agent) of
'true' -> kz_doc:account_db(Agent);
'false' -> kapps_call:account_db(Agent)
case is_thief(Agent) of
'true' -> kapps_call:account_db(Agent);
'false' -> kz_doc:account_db(Agent)
end.

-spec record_calls(agent()) -> boolean().
record_calls(Agent) ->
kz_json:is_json_object(Agent)
not is_thief(Agent)
andalso kz_json:is_true(<<"record_calls">>, Agent, 'false').

-spec is_thief(agent()) -> boolean().
Expand All @@ -1243,6 +1243,7 @@ stop_agent_leg(ACallId, ACtrlQ) ->
lager:debug("sending hangup to ~s: ~s", [ACallId, ACtrlQ]),
kapi_dialplan:publish_command(ACtrlQ, Command).

-spec find_account_id(kz_json:object()) -> kz_term:api_ne_binary().
find_account_id(JObj) ->
case kz_doc:account_id(JObj) of
'undefined' -> kz_util:format_account_id(kz_doc:account_db(JObj), 'raw');
Expand Down
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_announcements_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ maybe_start_announcements(Manager, Call, Props) ->
%% @doc Stop an announcements child process
%% @end
%%------------------------------------------------------------------------------
-spec stop_announcements(pid()) -> 'ok' | {'error', atom()}.
-spec stop_announcements(pid()) -> kz_types:sup_terminatechild_ret().
stop_announcements(Pid) ->
supervisor:terminate_child(?SERVER, Pid).

Expand Down
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ flush_call_stat(CallId) ->
acdc_stats:call_abandoned(kz_json:get_value(<<"Account-ID">>, Call)
,kz_json:get_value(<<"Queue-ID">>, Call)
,CallId
,'INTERNAL_ERROR'
,?ABANDON_INTERNAL_ERROR
),
io:format("setting call to 'abandoned'~n", [])
end.
Expand Down
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_queue_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ cdr_url(ServerRef) ->
init([WorkerSup, MgrPid, AccountId, QueueId]) ->
kz_util:put_callid(<<"statem_", QueueId/binary, "_", (kz_term:to_binary(self()))/binary>>),

webseq:start(?WSD_ID),
_ = webseq:start(?WSD_ID),
webseq:reg_who(?WSD_ID, self(), iolist_to_binary([<<"qFSM">>, pid_to_list(self())])),

AccountDb = kz_util:format_account_db(AccountId),
Expand Down
4 changes: 2 additions & 2 deletions applications/acdc/src/acdc_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ call_waiting(AccountId, QueueId, CallId, CallerIdName, CallerIdNumber, CallerPri
call_state_change(AccountId, 'waiting', Prop),
'ok' = kz_amqp_worker:cast(Prop, fun kapi_acdc_stats:publish_call_waiting/1).

-spec call_abandoned(kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary(), atom()) -> 'ok'.
-spec call_abandoned(kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary()) -> 'ok'.
call_abandoned(AccountId, QueueId, CallId, Reason) ->
Prop = props:filter_undefined(
[{<<"Account-ID">>, AccountId}
Expand Down Expand Up @@ -1012,7 +1012,7 @@ update_call_stat(Id, Updates, Props) ->

call_state_change(AccountId, Status, Prop) ->
Body = kz_json:normalize(kz_json:from_list([{<<"Event">>, <<"call_status_change">>}
,{<<"Status">>, Status}
,{<<"Status">>, kz_term:to_binary(Status)}
| Prop
])),
kz_edr:event(?APP_NAME, ?APP_VERSION, 'ok', 'info', Body, AccountId).
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ send_cdr(Url, JObj, Retries) ->
end.

%% Returns the list of agents configured for the queue
-spec agents_in_queue(kz_term:ne_binary(), kz_term:ne_binary()) -> kz_json:path().
-spec agents_in_queue(kz_term:ne_binary(), kz_term:ne_binary()) -> kz_json:objects().
agents_in_queue(AcctDb, QueueId) ->
case kz_datamgr:get_results(AcctDb, <<"queues/agents_listing">>
,[{'startkey', [QueueId]}
Expand Down
2 changes: 1 addition & 1 deletion applications/acdc/src/kapi_acdc_agent.erl
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ unbind_q(Q, {AcctId, AgentId, Status}, 'undefined') ->
_ = kz_amqp_util:unbind_q_from_kapps(Q, sync_req_routing_key(AcctId, AgentId)),
kz_amqp_util:unbind_q_from_kapps(Q, stats_req_routing_key(AcctId));
unbind_q(Q, {_, AgentId, _}=Ids, ['member_connect_win'|T]) ->
kz_amqp_util:unbind_q_from_kapps(Q, member_connect_win_routing_key(AgentId)),
_ = kz_amqp_util:unbind_q_from_kapps(Q, member_connect_win_routing_key(AgentId)),
unbind_q(Q, Ids, T);
unbind_q(Q, {AcctId, AgentId, Status}=Ids, ['status'|T]) ->
_ = kz_amqp_util:unbind_q_from_kapps(Q, agent_status_routing_key(AcctId, AgentId, Status)),
Expand Down
16 changes: 8 additions & 8 deletions applications/acdc/src/kapi_acdc_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -657,21 +657,21 @@ unbind_q(Q, Props) ->
unbind_q(Q, AcctId, QID, AID, props:get_value('restrict_to', Props)).

unbind_q(Q, AcctId, QID, AID, 'undefined') ->
kz_amqp_util:unbind_q_from_kapps(Q, call_stat_routing_key(AcctId, QID)),
kz_amqp_util:unbind_q_from_kapps(Q, status_stat_routing_key(AcctId, AID)),
kz_amqp_util:unbind_q_from_kapps(Q, query_call_stat_routing_key(AcctId, QID)),
kz_amqp_util:unbind_q_from_kapps(Q, query_status_stat_routing_key(AcctId, AID));
_ = kz_amqp_util:unbind_q_from_kapps(Q, call_stat_routing_key(AcctId, QID)),
_ = kz_amqp_util:unbind_q_from_kapps(Q, status_stat_routing_key(AcctId, AID)),
_ = kz_amqp_util:unbind_q_from_kapps(Q, query_call_stat_routing_key(AcctId, QID)),
_ = kz_amqp_util:unbind_q_from_kapps(Q, query_status_stat_routing_key(AcctId, AID));
unbind_q(Q, AcctId, QID, AID, ['call_stat'|L]) ->
kz_amqp_util:unbind_q_from_kapps(Q, call_stat_routing_key(AcctId, QID)),
_ = kz_amqp_util:unbind_q_from_kapps(Q, call_stat_routing_key(AcctId, QID)),
unbind_q(Q, AcctId, QID, AID, L);
unbind_q(Q, AcctId, QID, AID, ['status_stat'|L]) ->
kz_amqp_util:unbind_q_from_kapps(Q, status_stat_routing_key(AcctId, AID)),
_ = kz_amqp_util:unbind_q_from_kapps(Q, status_stat_routing_key(AcctId, AID)),
unbind_q(Q, AcctId, QID, AID, L);
unbind_q(Q, AcctId, QID, AID, ['query_call_stat'|L]) ->
kz_amqp_util:unbind_q_from_kapps(Q, query_call_stat_routing_key(AcctId, QID)),
_ = kz_amqp_util:unbind_q_from_kapps(Q, query_call_stat_routing_key(AcctId, QID)),
unbind_q(Q, AcctId, QID, AID, L);
unbind_q(Q, AcctId, QID, AID, ['query_status_stat'|L]) ->
kz_amqp_util:unbind_q_from_kapps(Q, query_status_stat_routing_key(AcctId, AID)),
_ = kz_amqp_util:unbind_q_from_kapps(Q, query_status_stat_routing_key(AcctId, AID)),
unbind_q(Q, AcctId, QID, AID, L);
unbind_q(Q, AcctId, QID, AID, [_|L]) ->
unbind_q(Q, AcctId, QID, AID, L);
Expand Down
4 changes: 4 additions & 0 deletions core/kazoo_stdlib/src/kz_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
-type sup_startchild_ret() :: {'ok', sup_child_id()} |
{'ok', sup_child_id(), any()} |
{'error', sup_startchild_err()}.
-type sup_terminatechild_err() :: 'not_found' | 'simple_one_for_one'.
-type sup_terminatechild_ret() :: 'ok' | {'error', sup_terminatechild_err()}.
-type sup_deletechild_err() :: 'running' | 'restarting' | 'not_found' |
'simple_one_for_one'.
-type sup_deletechild_ret() :: 'ok' | {'error', sup_deletechild_err()}.
Expand Down Expand Up @@ -138,6 +140,8 @@
,sup_child_id/0
,sup_startchild_err/0
,sup_startchild_ret/0
,sup_terminatechild_err/0
,sup_terminatechild_ret/0
,sup_deletechild_err/0
,sup_deletechild_ret/0
,startlink_err/0
Expand Down

0 comments on commit 542e518

Please sign in to comment.