Skip to content

Commit 5b6410a

Browse files
author
Matthew Sackman
committed
Some cosmetics; Some consistency of ordering; There is no good reason why delayed restart shouldn't also support intrinsic. Added.
1 parent 9d8fd52 commit 5b6410a

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/supervisor2.erl

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
%% terminated as per the shutdown component of the child_spec.
1010
%%
1111
%% 3) child specifications can contain, as the restart type, a tuple
12-
%% {permanent, Delay} | {transient, Delay} where Delay >= 0. The
13-
%% delay, in seconds, indicates what should happen if a child, upon
14-
%% being restarted, exceeds the MaxT and MaxR parameters. Thus, if
15-
%% a child exits, it is restarted as normal. If it exits
16-
%% sufficiently quickly and often to exceed the boundaries set by
17-
%% the MaxT and MaxR parameters, and a Delay is specified, then
18-
%% rather than stopping the supervisor, the supervisor instead
19-
%% continues and tries to start up the child again, Delay seconds
20-
%% later.
12+
%% {permanent, Delay} | {transient, Delay} | {intrinsic, Delay}
13+
%% where Delay >= 0 (see point (4) below for intrinsic). The delay,
14+
%% in seconds, indicates what should happen if a child, upon being
15+
%% restarted, exceeds the MaxT and MaxR parameters. Thus, if a
16+
%% child exits, it is restarted as normal. If it exits sufficiently
17+
%% quickly and often to exceed the boundaries set by the MaxT and
18+
%% MaxR parameters, and a Delay is specified, then rather than
19+
%% stopping the supervisor, the supervisor instead continues and
20+
%% tries to start up the child again, Delay seconds later.
2121
%%
2222
%% Note that you can never restart more frequently than the MaxT
2323
%% and MaxR parameters allow: i.e. you must wait until *both* the
@@ -540,12 +540,13 @@ do_restart(Type, {shutdown, _}, Child, State) ->
540540
del_child_and_maybe_shutdown(Type, Child, State);
541541
do_restart(Type, shutdown, Child = #child{child_type = supervisor}, State) ->
542542
del_child_and_maybe_shutdown(Type, Child, State);
543+
do_restart({RestartType, Delay}, Reason, Child, State)
544+
when RestartType =:= transient orelse RestartType =:= intrinsic ->
545+
do_restart_delay({RestartType, Delay}, Reason, Child, State);
543546
do_restart(Type, Reason, Child, State) when Type =:= transient orelse
544547
Type =:= intrinsic ->
545548
report_error(child_terminated, Reason, Child, State#state.name),
546549
restart(Child, State);
547-
do_restart({transient = RestartType, Delay}, Reason, Child, State) ->
548-
do_restart_delay({RestartType, Delay}, Reason, Child, State);
549550
do_restart(temporary, Reason, Child, State) ->
550551
report_error(child_terminated, Reason, Child, State#state.name),
551552
NState = state_del_child(Child, State),
@@ -557,8 +558,8 @@ do_restart_delay({RestartType, Delay}, Reason, Child, State) ->
557558
{ok, NState};
558559
{terminate, NState} ->
559560
_TRef = erlang:send_after(trunc(Delay*1000), self(),
560-
{delayed_restart,
561-
{{RestartType, Delay}, Reason, Child}}),
561+
{delayed_restart,
562+
{{RestartType, Delay}, Reason, Child}}),
562563
{ok, state_del_child(Child, NState)}
563564
end.
564565

@@ -916,7 +917,8 @@ supname(N,_) -> N.
916917
%%% Func is {Mod, Fun, Args} == {atom, atom, list}
917918
%%% RestartType is permanent | temporary | transient |
918919
%%% intrinsic | {permanent, Delay} |
919-
%%% {transient, Delay} where Delay >= 0
920+
%%% {transient, Delay} | {intrinsic, Delay}
921+
%% where Delay >= 0
920922
%%% Shutdown = integer() | infinity | brutal_kill
921923
%%% ChildType = supervisor | worker
922924
%%% Modules = [atom()] | dynamic
@@ -967,6 +969,7 @@ validRestartType(temporary) -> true;
967969
validRestartType(transient) -> true;
968970
validRestartType(intrinsic) -> true;
969971
validRestartType({permanent, Delay}) -> validDelay(Delay);
972+
validRestartType({intrinsic, Delay}) -> validDelay(Delay);
970973
validRestartType({transient, Delay}) -> validDelay(Delay);
971974
validRestartType(RestartType) -> throw({invalid_restart_type,
972975
RestartType}).

0 commit comments

Comments
 (0)