Skip to content

Commit

Permalink
PISTON-352: track endpoints in acdc_agent_fsm better
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfinke committed Jun 5, 2020
1 parent 2fba613 commit bc91c0a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion applications/acdc/src/acdc_agent_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -1796,6 +1796,20 @@ 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_owner_id/2, kzd_devices:owner_id(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()}.
Expand Down

0 comments on commit bc91c0a

Please sign in to comment.