fix endpoint

This commit is contained in:
anlicheng 2026-05-11 18:31:40 +08:00
parent 0b066e4bb0
commit b496951f73
2 changed files with 24 additions and 15 deletions

View File

@ -10,6 +10,7 @@
-export([start_link/0]).
-export([ensured_endpoint_started/1, delete_endpoint/1]).
-export([start_endpoints/1]).
-export([init/1]).
@ -29,21 +30,15 @@ start_link() ->
%% modules => modules()} % optional
init([]) ->
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
Endpoints = iot_api_client:get_all_endpoints(),
ChildSpecs = lists:filtermap(fun(EndpointInfo) ->
case endpoint:endpoint_record(EndpointInfo) of
error ->
false;
{ok, Endpoint} ->
case endpoint:is_support(endpoint:get_protocol(Endpoint)) of
true ->
{true, child_spec(Endpoint)};
false ->
false
end
end
end, Endpoints),
{ok, {SupFlags, ChildSpecs}}.
{ok, {SupFlags, []}}.
-spec start_endpoints(Endpoints :: list()) -> ok.
start_endpoints(Endpoints) when is_list(Endpoints) ->
lists:foreach(fun(Endpoint) ->
Spec = child_spec(Endpoint),
{ok, _} = supervisor:start_child(?MODULE, Spec)
end, Endpoints),
ok.
-spec ensured_endpoint_started(Endpoint :: #endpoint{}) -> {ok, Pid :: pid()} | {error, Reason :: any()}.
ensured_endpoint_started(Endpoint = #endpoint{}) ->

View File

@ -22,6 +22,8 @@ start(_StartType, _StartArgs) ->
iot_mnesia:init()
end,
start_endpoints(),
%% http服务 supervisor simulator API
start_http_server(),
@ -36,6 +38,18 @@ stop(_State) ->
%% internal functions
start_endpoints() ->
EndpointInfos = iot_api_client:get_all_endpoints(),
Endpoints = lists:filtermap(fun(EndpointInfo) ->
case endpoint:endpoint_record(EndpointInfo) of
error ->
false;
{ok, Endpoint} ->
{true, Endpoint}
end
end, EndpointInfos),
ok = endpoint_adapter_sup:start_endpoints(Endpoints).
start_http_server() ->
{ok, Props} = application:get_env(iot, http_server),
Acceptors = proplists:get_value(acceptors, Props, 50),