ekfa/apps/efka/src/efka_sup.erl
2026-05-11 23:21:19 +08:00

92 lines
2.7 KiB
Erlang

%%%-------------------------------------------------------------------
%% @doc efka top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(efka_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
-define(SERVER, ?MODULE).
-spec start_link() -> {ok, pid()} | ignore | {error, term()}.
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
-spec init(list()) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
init([]) ->
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
ChildSpecs = [
#{
id => 'efka_logger',
start => {'efka_logger', start_link, ["deploy_log"]},
restart => permanent,
shutdown => 2000,
type => worker,
modules => ['efka_logger']
},
#{
id => 'efka_service_sup',
start => {'efka_service_sup', start_link, []},
restart => permanent,
shutdown => 2000,
type => supervisor,
modules => ['efka_service_sup']
},
#{
id => efka_service_model,
start => {efka_service_model, start_link, []},
restart => permanent,
shutdown => 5000,
type => worker,
modules => ['efka_service_model']
},
#{
id => 'efka_subscription',
start => {'efka_subscription', start_link, []},
restart => permanent,
shutdown => 2000,
type => worker,
modules => ['efka_subscription']
},
#{
id => 'efka_iot_client',
start => {'efka_iot_client', start_link, []},
restart => permanent,
shutdown => 2000,
type => worker,
modules => ['efka_iot_client']
},
#{
id => 'efka_iot_heartbeat',
start => {'efka_iot_heartbeat', start_link, []},
restart => permanent,
shutdown => 2000,
type => worker,
modules => ['efka_iot_heartbeat']
}
],
{ok, {SupFlags, ChildSpecs}}.
%% internal functions