iot_cloud/apps/iot/src/iot_sup.erl
2024-01-12 21:52:28 +08:00

49 lines
1.5 KiB
Erlang

%%%-------------------------------------------------------------------
%% @doc iot top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(iot_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
-define(SERVER, ?MODULE).
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%% sup_flags() = #{strategy => strategy(), % optional
%% intensity => non_neg_integer(), % optional
%% period => pos_integer()} % optional
%% child_spec() = #{id => child_id(), % mandatory
%% start => mfargs(), % mandatory
%% restart => restart(), % optional
%% shutdown => shutdown(), % optional
%% type => worker(), % optional
%% modules => modules()} % optional
init([]) ->
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
Specs = [
#{
id => 'iot_zd_endpoint',
start => {'iot_zd_endpoint', start_link, []},
restart => permanent,
shutdown => 2000,
type => worker,
modules => ['iot_zd_endpoint']
}
],
{ok, {SupFlags, pools() ++ Specs}}.
%% internal functions
pools() ->
{ok, Pools} = application:get_env(iot, pools),
lists:map(fun({Name, PoolArgs, WorkerArgs}) ->
poolboy:child_spec(Name, [{name, {local, Name}}|PoolArgs], WorkerArgs)
end, Pools).