From b394ad361efd3986876f77c7260dc841252d2d4a Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 31 Oct 2014 14:02:06 -0700 Subject: [PATCH 1/2] Make default restart intensity values configurable Add two application parameters, `max_restart` and `max_seconds_between_restarts`, to allow an external application to configure these values. See README.md for details. --- README.md | 12 +++++++++++- src/epna_sup.erl | 7 ++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7b7d74d..ede1fb2 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,19 @@ connect. There are several parameters that are required. name of the function and any arguments needed to be passed to that function. There is an example below. +episcina also has two optional parameters: + +* `max_restarts`: the number of restarts that are allowed + to occur within `max_seconds_between_restarts` seconds. (Default: 1000) +* `max_seconds_between_restarts`: If more than `max_restarts` restarts + occur within `max_seconds_between_restarts` seconds, the episcina supervisor + will terminate all its child processes, then itself. (Default: 3600) + #### sys.config file example: - {episcina, [{pools, [{db1, +{episcina, [{max_restarts, 2000}, + {max_seconds_between_restarts, 7200}, + {pools, [{db1, [{size, 10}, {timeout, 10000}, {connect_provider, {pgsql, connect, diff --git a/src/epna_sup.erl b/src/epna_sup.erl index b0aa685..6ce1803 100644 --- a/src/epna_sup.erl +++ b/src/epna_sup.erl @@ -35,10 +35,11 @@ start_pool(Name, Size, Timeout, ConnectFun, CloseFun) -> %%@private init([]) -> RestartStrategy = simple_one_for_one, - MaxRestarts = 1000, - MaxSecondsBetweenRestarts = 3600, - SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, + MaxR = application:get_env(episcina, max_restarts, 1000), + MaxT = application:get_env(episcina, max_seconds_between_restarts, 3600), + + SupFlags = {RestartStrategy, MaxR, MaxT}, Restart = permanent, Shutdown = 2000, From e6220d1ab18fe05b82afdb49babe11c18486d088 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 3 Nov 2014 11:28:45 -0800 Subject: [PATCH 2/2] Avoid using application:get_env/3, since R15 doesn't have it --- src/epna_sup.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/epna_sup.erl b/src/epna_sup.erl index 6ce1803..61b13cf 100644 --- a/src/epna_sup.erl +++ b/src/epna_sup.erl @@ -36,8 +36,8 @@ start_pool(Name, Size, Timeout, ConnectFun, CloseFun) -> init([]) -> RestartStrategy = simple_one_for_one, - MaxR = application:get_env(episcina, max_restarts, 1000), - MaxT = application:get_env(episcina, max_seconds_between_restarts, 3600), + MaxR = get_env(max_restarts, 1000), + MaxT = get_env(max_seconds_between_restarts, 3600), SupFlags = {RestartStrategy, MaxR, MaxT}, @@ -53,3 +53,11 @@ init([]) -> %%%=================================================================== %%% Internal functions %%%=================================================================== + +get_env(Key, Default) -> + case application:get_env(episcina, Key) of + undefined -> + Default; + {ok, Value} -> + Value + end.