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..61b13cf 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 = get_env(max_restarts, 1000), + MaxT = get_env(max_seconds_between_restarts, 3600), + + SupFlags = {RestartStrategy, MaxR, MaxT}, Restart = permanent, Shutdown = 2000, @@ -52,3 +53,11 @@ init([]) -> %%%=================================================================== %%% Internal functions %%%=================================================================== + +get_env(Key, Default) -> + case application:get_env(episcina, Key) of + undefined -> + Default; + {ok, Value} -> + Value + end.