-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathid_server_2_sup.erl
More file actions
87 lines (69 loc) · 2.98 KB
/
id_server_2_sup.erl
File metadata and controls
87 lines (69 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-module(id_server_2_sup).
-behaviour(supervisor).
%% API
-export([start_link/0]).
%% Supervisor callbacks
-export([init/1]).
-define(TIMEOUT, 5000). % 5 seconds
%%%=============================================================================
%%% API functions
%%%=============================================================================
%% @doc Start the supervisor.
-spec start_link() -> {ok, pid()} |
ignore |
{error, {already_started, pid()} |
{shutdown, term()} |
term()}.
start_link() ->
supervisor:start_link({local, ?MODULE}, % Name
?MODULE, % Callback module
#{}). % Config
%%%=============================================================================
%%% Supervisor callbacks
%%%=============================================================================
%% @doc Return the supervisor's initial configuration.
-spec init(Config :: #{}) ->
{ok, {SupFlags :: {supervisor:strategy(),
MaxR :: non_neg_integer(),
MaxT :: pos_integer()},
ChildSpecs :: [supervisor:child_spec()]}} |
ignore |
{ok, {{supervisor:strategy(), non_neg_integer(), pos_integer()},
[supervisor:child_spec()]}}.
init(_Config = #{}) ->
{ok, {
% Global options
{
% Supervisor strategy: what to do with other children when a child
% is restarted.
% - one_for_one: leave them
% - one_for_all: restart all of them
% - rest_for_one: restart only the ones after the restarted child
one_for_one,
% If more than 5 restarts occur within 10 seconds, the supervisor
% terminates all child processes and then itself.
5, 10},
% Child processes
[
child(id_server_2, start_link, [])
]
}}.
%%%=============================================================================
%%% Internal functions
%%%=============================================================================
-spec child(Mod :: module(),
Fun :: atom(),
Args :: [term()]) -> supervisor:child_spec().
child(Mod, Fun, Args) ->
% For Erlang/OTP >= 18.0:
#{id => Mod, % Id of the child within the supervisor.
start => {Mod, Fun, Args}, % How to start the child.
restart => permanent, % Should we restart the child?
% - permanent = always
% - transient = only if crashed
% - temporary = never
shutdown => ?TIMEOUT, % Time to wait for children when terminating.
type => worker, % Child type: worker | supervisor.
modules => [Mod]}. % Modules used by the child process.
% For any Erlang/OTP:
%{Mod, {Mod, Fun, Args}, permanent, ?TIMEOUT, worker, [Mod]}.