From 7f5cb36e32fce07ee8ba1338b22a06fb0786cfe1 Mon Sep 17 00:00:00 2001 From: Daniel Finke Date: Fri, 5 Jun 2020 01:19:36 +0000 Subject: [PATCH] PISTON-352: track endpoints in acdc_agent_fsm better --- applications/acdc/src/acdc_agent_fsm.erl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/applications/acdc/src/acdc_agent_fsm.erl b/applications/acdc/src/acdc_agent_fsm.erl index 6ccf1bc150d..412d30dca8f 100644 --- a/applications/acdc/src/acdc_agent_fsm.erl +++ b/applications/acdc/src/acdc_agent_fsm.erl @@ -1782,7 +1782,7 @@ maybe_add_endpoint(EPId, EP, EPs, AccountId) -> case lists:partition(fun(E) -> find_endpoint_id(E) =:= EPId end, EPs) of {[], _} -> lager:debug("endpoint ~s not in our list, adding it", [EPId]), - [begin monitor_endpoint(EP, AccountId), EP end | EPs]; + [begin monitor_endpoint(convert_to_endpoint(EP), AccountId), EP end | EPs]; {_, _} -> EPs end. @@ -1796,6 +1796,19 @@ maybe_remove_endpoint(EPId, EPs, AccountId) -> EPs1 end. +-spec convert_to_endpoint(kz_json:object()) -> kz_term:api_object(). +convert_to_endpoint(EPDoc) -> + Setters = [{fun kapps_call:set_account_id/2, kz_doc:account_id(EPDoc)} + ,{fun kapps_call:set_account_db/2, kz_doc:account_db(EPDoc)} + ,{fun kapps_call:set_resource_type/2, ?RESOURCE_TYPE_AUDIO} + ], + + Call = kapps_call:exec(Setters, kapps_call:new()), + case kz_endpoint:build(kz_doc:id(EPDoc), [], Call) of + {'ok', EP} -> EP; + {'error', _} -> 'undefined' + end. + -spec get_endpoints(kz_json:objects(), kapps_call:call(), kz_term:api_binary(), kz_term:api_binary()) -> {'ok', kz_json:objects()} | {'error', any()}.