diff options
author | Matthew Sackman <matthew@rabbitmq.com> | 2012-03-21 13:17:52 +0000 |
---|---|---|
committer | Matthew Sackman <matthew@rabbitmq.com> | 2012-03-21 13:17:52 +0000 |
commit | b8d1bb86d576a2b1f0cd989af27d9b8b657878e7 (patch) | |
tree | 437f6f875e82f8971bde26f534151cb79df0dfd9 | |
parent | 33bf55fd7ea946b467262a9fe40aae03dc1c00fa (diff) | |
download | rabbitmq-server-b8d1bb86d576a2b1f0cd989af27d9b8b657878e7.tar.gz |
Some cosmetics; Some consistency of ordering; There is no good reason why delayed restart shouldn't also support intrinsic. Added.
-rw-r--r-- | src/supervisor2.erl | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/supervisor2.erl b/src/supervisor2.erl index d3851c4b..fd5f0f30 100644 --- a/src/supervisor2.erl +++ b/src/supervisor2.erl @@ -9,15 +9,15 @@ %% terminated as per the shutdown component of the child_spec. %% %% 3) child specifications can contain, as the restart type, a tuple -%% {permanent, Delay} | {transient, Delay} where Delay >= 0. The -%% delay, in seconds, indicates what should happen if a child, upon -%% being restarted, exceeds the MaxT and MaxR parameters. Thus, if -%% a child exits, it is restarted as normal. If it exits -%% sufficiently quickly and often to exceed the boundaries set by -%% the MaxT and MaxR parameters, and a Delay is specified, then -%% rather than stopping the supervisor, the supervisor instead -%% continues and tries to start up the child again, Delay seconds -%% later. +%% {permanent, Delay} | {transient, Delay} | {intrinsic, Delay} +%% where Delay >= 0 (see point (4) below for intrinsic). The delay, +%% in seconds, indicates what should happen if a child, upon being +%% restarted, exceeds the MaxT and MaxR parameters. Thus, if a +%% child exits, it is restarted as normal. If it exits sufficiently +%% quickly and often to exceed the boundaries set by the MaxT and +%% MaxR parameters, and a Delay is specified, then rather than +%% stopping the supervisor, the supervisor instead continues and +%% tries to start up the child again, Delay seconds later. %% %% Note that you can never restart more frequently than the MaxT %% and MaxR parameters allow: i.e. you must wait until *both* the @@ -540,12 +540,13 @@ do_restart(Type, {shutdown, _}, Child, State) -> del_child_and_maybe_shutdown(Type, Child, State); do_restart(Type, shutdown, Child = #child{child_type = supervisor}, State) -> del_child_and_maybe_shutdown(Type, Child, State); +do_restart({RestartType, Delay}, Reason, Child, State) + when RestartType =:= transient orelse RestartType =:= intrinsic -> + do_restart_delay({RestartType, Delay}, Reason, Child, State); do_restart(Type, Reason, Child, State) when Type =:= transient orelse Type =:= intrinsic -> report_error(child_terminated, Reason, Child, State#state.name), restart(Child, State); -do_restart({transient = RestartType, Delay}, Reason, Child, State) -> - do_restart_delay({RestartType, Delay}, Reason, Child, State); do_restart(temporary, Reason, Child, State) -> report_error(child_terminated, Reason, Child, State#state.name), NState = state_del_child(Child, State), @@ -557,8 +558,8 @@ do_restart_delay({RestartType, Delay}, Reason, Child, State) -> {ok, NState}; {terminate, NState} -> _TRef = erlang:send_after(trunc(Delay*1000), self(), - {delayed_restart, - {{RestartType, Delay}, Reason, Child}}), + {delayed_restart, + {{RestartType, Delay}, Reason, Child}}), {ok, state_del_child(Child, NState)} end. @@ -916,7 +917,8 @@ supname(N,_) -> N. %%% Func is {Mod, Fun, Args} == {atom, atom, list} %%% RestartType is permanent | temporary | transient | %%% intrinsic | {permanent, Delay} | -%%% {transient, Delay} where Delay >= 0 +%%% {transient, Delay} | {intrinsic, Delay} +%% where Delay >= 0 %%% Shutdown = integer() | infinity | brutal_kill %%% ChildType = supervisor | worker %%% Modules = [atom()] | dynamic @@ -967,6 +969,7 @@ validRestartType(temporary) -> true; validRestartType(transient) -> true; validRestartType(intrinsic) -> true; validRestartType({permanent, Delay}) -> validDelay(Delay); +validRestartType({intrinsic, Delay}) -> validDelay(Delay); validRestartType({transient, Delay}) -> validDelay(Delay); validRestartType(RestartType) -> throw({invalid_restart_type, RestartType}). |