Mail info and log status update

This commit is contained in:
Fabio Salvini 2017-06-17 10:05:35 +02:00
parent 9b13aa6cbc
commit d3d42097d9
2 changed files with 11 additions and 4 deletions

View File

@ -33,11 +33,18 @@ init([]) ->
{ok, #state{statuses = Statuses}}. {ok, #state{statuses = Statuses}}.
handle_info({watcher_init, File}, State = #state{statuses = Statuses}) -> handle_info({watcher_init, File}, State = #state{statuses = Statuses}) ->
ets:insert(Statuses, {File, active}), case ets:lookup(Statuses, File) of
%% If the File has been removed, do nothing
[] -> ok;
_ -> ets:insert(Statuses, {File, active})
end,
{noreply, State}; {noreply, State};
handle_info({watcher_terminate, File}, State = #state{statuses = Statuses}) -> handle_info({watcher_terminate, File}, State = #state{statuses = Statuses}) ->
%% TODO: do not update it if not present case ets:lookup(Statuses, File) of
ets:insert(Statuses, {File, inactive}), %% If the File has been removed, do nothing
[] -> ok;
_ -> ets:insert(Statuses, {File, inactive})
end,
{noreply, State}; {noreply, State};
handle_info(_Msg, State) -> handle_info(_Msg, State) ->
{noreply, State}. {noreply, State}.

View File

@ -37,7 +37,7 @@ send_email(File, Text) ->
Sender = proplists:get_value(sender, EmailConfig), Sender = proplists:get_value(sender, EmailConfig),
DefaultReceiver = proplists:get_value(default_receiver, EmailConfig), DefaultReceiver = proplists:get_value(default_receiver, EmailConfig),
Connection = proplists:get_value(connection, EmailConfig), Connection = proplists:get_value(connection, EmailConfig),
error_logger:info_report("Sending email for file ~s with text: ~n~s~n", [File, Text]), error_logger:info_msg("Sending email for file ~s with text: ~n~s~n", [File, Text]),
gen_smtp_client:send_blocking( gen_smtp_client:send_blocking(
{Sender, [DefaultReceiver], {Sender, [DefaultReceiver],
io_lib:format("Subject: Error notification\r\nFrom: Fabio\r\n\r\nLogfile: ~s~nError: ~n~s~n", [File, Text])}, io_lib:format("Subject: Error notification\r\nFrom: Fabio\r\n\r\nLogfile: ~s~nError: ~n~s~n", [File, Text])},