Packages
launchdarkly_server_sdk
3.9.0
3.11.0
3.10.1
3.9.0
3.8.1
3.8.0
3.7.2
3.7.1
3.7.0
3.6.0
3.5.0
3.4.0
3.3.1
3.3.0
3.2.0
3.1.0
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.1.2
2.1.1
2.1.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.6.0
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.3
1.1.2
1.1.1
retired
1.1.0
retired
1.0.1
retired
1.0.0
retired
1.0.0-beta4
retired
1.0.0-beta3
retired
1.0.0-beta2
retired
LaunchDarkly SDK for Erlang
Current section
Files
Jump to
Current section
Files
src/ldclient_instance_sup.erl
%%-------------------------------------------------------------------
%% @doc Instance supervisor
%% @private
%% @end
%%-------------------------------------------------------------------
-module(ldclient_instance_sup).
-behaviour(supervisor).
%% Supervision
-export([start_link/5, init/1, child_spec/1, child_spec/2]).
%% Helper macro for declaring children of supervisor
-define(CHILD(Id, Module, Args, Type), {Id, {Module, start_link, Args}, permanent, 5000, Type, [Module]}).
child_spec(Args) -> child_spec(?MODULE, Args).
child_spec(Id, Args) ->
#{
id => Id,
start => {?MODULE, start_link, Args},
restart => permanent,
shutdown => 5000, % shutdown time
type => supervisor,
modules => [?MODULE]
}.
%%===================================================================
%% Supervision
%%===================================================================
-spec start_link(
SupName :: atom(),
UpdateSupName :: atom(),
UpdateWorkerModule :: atom(),
EventSupName :: atom(),
Tag :: atom()
) ->
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}.
start_link(SupName, UpdateSupName, UpdateWorkerModule, EventSupName, Tag) ->
error_logger:info_msg("Starting instance supervisor for ~p with name ~p", [Tag, SupName]),
supervisor:start_link({local, SupName}, ?MODULE, [UpdateSupName, UpdateWorkerModule, EventSupName, Tag]).
-spec init(Args :: term()) ->
{ok, {{supervisor:strategy(), non_neg_integer(), pos_integer()}, [supervisor:child_spec()]}}.
init([UpdateSupName, UpdateWorkerModule, EventSupName, Tag]) ->
% Allow up to 10 restarts in 60 seconds before giving up.
% This provides resilience for transient failures in child supervisors
% (update processor, events, storage) while preventing infinite restart loops.
{ok, {{one_for_one, 10, 60}, children(UpdateSupName, UpdateWorkerModule, EventSupName, Tag)}}.
%%===================================================================
%% Internal functions
%%===================================================================
-spec children(
UpdateSupName :: atom(),
UpdateWorkerModule :: atom(),
EventSupName :: atom(),
Tag :: atom()
) -> [supervisor:child_spec()].
children(UpdateSupName, UpdateWorkerModule, EventSupName, Tag) ->
UpdateSup = ?CHILD(ldclient_update_sup, ldclient_update_sup, [UpdateSupName, UpdateWorkerModule], supervisor),
EventSup = ?CHILD(ldclient_event_sup, ldclient_event_sup, [EventSupName, Tag], supervisor),
[UpdateSup, EventSup].