Fallback timer for infinite consecutive errors
This commit is contained in:
parent
b11ab480b9
commit
65a077f022
2
TODO.md
2
TODO.md
|
@ -1,7 +1,7 @@
|
||||||
TODO
|
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.
|
- Limit number of emails that can be sent in a period of time.
|
||||||
- Store the logfiles in a configuration file.
|
- Store the logfiles in a configuration file.
|
||||||
- gen_fsm for gatherer?
|
- gen_fsm for gatherer?
|
||||||
|
|
|
@ -17,19 +17,22 @@ handle_info({log_line, Text}, [off, Log = #log{error_regex = ErrorRegex}]) ->
|
||||||
case isError(Text, ErrorRegex) of
|
case isError(Text, ErrorRegex) of
|
||||||
true ->
|
true ->
|
||||||
{ok, Timer} = timer:send_after(1000, {timeout}),
|
{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]}
|
false -> {noreply, [off, Log]}
|
||||||
end;
|
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
|
case isError(Text, ErrorRegex) of
|
||||||
true ->
|
true ->
|
||||||
timer:clean(Timer),
|
timer:cancel(Timer),
|
||||||
{ok, NewTimer} = timer:send_after(1000, {timeout}),
|
{ok, NewTimer} = timer:send_after(1000, {timeout}),
|
||||||
{noreply, [on, Log, Error ++ "\n" ++ Text, NewTimer]};
|
{noreply, [on, Log, Error ++ "\n" ++ Text, NewTimer, SafeTimer]};
|
||||||
false ->
|
false ->
|
||||||
{noreply, [on, Log, Error ++ "\n" ++ Text, Timer]}
|
{noreply, [on, Log, Error ++ "\n" ++ Text, Timer, SafeTimer]}
|
||||||
end;
|
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},
|
mailer ! {error, File, Error},
|
||||||
{noreply, [off, Log]}.
|
{noreply, [off, Log]}.
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
-export([start_link/0, init/1, terminate/2]).
|
-export([start_link/0, init/1, terminate/2]).
|
||||||
-export([handle_info/2, handle_cast/2, handle_call/3]).
|
-export([handle_info/2, handle_cast/2, handle_call/3]).
|
||||||
-export([code_change/3]).
|
-export([code_change/3]).
|
||||||
-export([email_subject/2]).
|
|
||||||
|
|
||||||
start_link() ->
|
start_link() ->
|
||||||
gen_server:start_link(?MODULE, [], []).
|
gen_server:start_link(?MODULE, [], []).
|
||||||
|
|
Loading…
Reference in New Issue
Block a user