Fallback timer for infinite consecutive errors

This commit is contained in:
Fabio Salvini 2017-06-26 19:47:43 +02:00
parent b11ab480b9
commit 65a077f022
3 changed files with 10 additions and 8 deletions

View File

@ -1,7 +1,7 @@
TODO
=====
- Manage problem of "infinite" consecutive errors.
- Allow to enable / disabled logfiles.
- Limit number of emails that can be sent in a period of time.
- Store the logfiles in a configuration file.
- gen_fsm for gatherer?

View File

@ -17,19 +17,22 @@ handle_info({log_line, Text}, [off, Log = #log{error_regex = ErrorRegex}]) ->
case isError(Text, ErrorRegex) of
true ->
{ok, Timer} = timer:send_after(1000, {timeout}),
{noreply, [on, Log, Text, Timer]};
{ok, SafeTimer} = timer:send_after(30000, {timeout}),
{noreply, [on, Log, Text, Timer, SafeTimer]};
false -> {noreply, [off, Log]}
end;
handle_info({log_line, Text}, [on, Log = #log{error_regex = ErrorRegex}, Error, Timer]) ->
handle_info({log_line, Text}, [on, Log = #log{error_regex = ErrorRegex}, Error, Timer, SafeTimer]) ->
case isError(Text, ErrorRegex) of
true ->
timer:clean(Timer),
timer:cancel(Timer),
{ok, NewTimer} = timer:send_after(1000, {timeout}),
{noreply, [on, Log, Error ++ "\n" ++ Text, NewTimer]};
{noreply, [on, Log, Error ++ "\n" ++ Text, NewTimer, SafeTimer]};
false ->
{noreply, [on, Log, Error ++ "\n" ++ Text, Timer]}
{noreply, [on, Log, Error ++ "\n" ++ Text, Timer, SafeTimer]}
end;
handle_info({timeout}, [on, Log = #log{file = File}, Error, _Timer]) ->
handle_info({timeout}, [on, Log = #log{file = File}, Error, Timer, SafeTimer]) ->
timer:cancel(Timer),
timer:cancel(SafeTimer),
mailer ! {error, File, Error},
{noreply, [off, Log]}.

View File

@ -6,7 +6,6 @@
-export([start_link/0, init/1, terminate/2]).
-export([handle_info/2, handle_cast/2, handle_call/3]).
-export([code_change/3]).
-export([email_subject/2]).
start_link() ->
gen_server:start_link(?MODULE, [], []).