52 lines
1.4 KiB
Erlang
52 lines
1.4 KiB
Erlang
-module(gmhc_connectors_sup).
|
|
-vsn("0.8.3").
|
|
-behavior(supervisor).
|
|
|
|
-export([ start_link/0
|
|
, init/1 ]).
|
|
|
|
-export([ start_first_connector/0
|
|
, start_connector/1
|
|
, add_restart_info/2 ]).
|
|
|
|
start_link() ->
|
|
case supervisor:start_link({local, ?MODULE}, ?MODULE, []) of
|
|
{ok, _} = Ok ->
|
|
RI = gmhc_watchdog:get_restart_info(),
|
|
maps:foreach(fun restart_connector/2, RI),
|
|
Ok;
|
|
Other ->
|
|
Other
|
|
end.
|
|
|
|
restart_connector({?MODULE, _}, Opts) ->
|
|
start_connector(Opts);
|
|
restart_connector(_, _) ->
|
|
ok.
|
|
|
|
start_first_connector() ->
|
|
start_connector(#{}).
|
|
|
|
start_connector(Opts0) ->
|
|
Opts = case maps:is_key(id, Opts0) of
|
|
true -> Opts0;
|
|
false -> Opts0#{id => gmhc_counters:add_read(connector)}
|
|
end,
|
|
supervisor:start_child(?MODULE, [Opts]).
|
|
|
|
add_restart_info(Id, Opts) ->
|
|
gmhc_watchdog:note_started({?MODULE, Id}, Opts).
|
|
|
|
init([]) ->
|
|
Mod = gmhc_connector,
|
|
SupFlags = #{ strategy => simple_one_for_one
|
|
, intensity => 3
|
|
, period => 10 },
|
|
ChildSpecs = [ #{ id => Mod
|
|
, start => {Mod, start_link, []}
|
|
, type => worker
|
|
, restart => transient
|
|
, shutdown => 5000
|
|
, modules => [Mod] } ],
|
|
{ok, {SupFlags, ChildSpecs}}.
|