Add queue details

This commit is contained in:
Fabio Salvini 2017-12-02 16:10:45 +01:00
parent c80d15cfe8
commit 1517c9c071

View File

@ -17,7 +17,7 @@
%% API %% API
-export([start_link/0]). -export([start_link/0]).
-export([queue/0, empty_queue/0, empty_file_queue/1]). -export([queue/0, queue_details/0, empty_queue/0, empty_file_queue/1]).
%% gen_server callbacks %% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@ -49,6 +49,16 @@ start_link() ->
queue() -> queue() ->
gen_server:call(mailer, {queue_count}). gen_server:call(mailer, {queue_count}).
%%--------------------------------------------------------------------
%% @doc
%% Get the queue details.
%%
%% @spec queue() -> {ok, Details}
%% @end
%%--------------------------------------------------------------------
queue_details() ->
gen_server:call(mailer, {queue_details}).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Delete all the mails from the queue. %% Delete all the mails from the queue.
@ -113,6 +123,9 @@ init([]) ->
handle_call({queue_count}, _From, State) -> handle_call({queue_count}, _From, State) ->
Count = length(emails_to_send()), Count = length(emails_to_send()),
{reply, Count, State}; {reply, Count, State};
handle_call({queue_details}, _From, State) ->
Details = dict:to_list(get_queue_details()),
{reply, Details, State};
handle_call({empty_queue}, _From, State) -> handle_call({empty_queue}, _From, State) ->
remove_all_emails(), remove_all_emails(),
{reply, ok, State}; {reply, ok, State};
@ -203,6 +216,33 @@ code_change(_OldVsn, State, _Extra) ->
%%%=================================================================== %%%===================================================================
%%% Internal functions %%% Internal functions
%%%=================================================================== %%%===================================================================
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Get the number of errors for each file.
%%
%% @spec queue_details() -> Dict
%% @end
%%--------------------------------------------------------------------
get_queue_details() ->
mnesia:activity(
transaction,
fun() ->
mnesia:foldl(
fun(#log_monitor_error{id = _Id, file = File, text = _Text}, Acc) ->
dict:update_counter(File, 1, Acc)
end, dict:new(), log_monitor_error)
end).
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Get all the emails that need to be sent.
%%
%% @spec emails_to_send() -> List
%% @end
%%--------------------------------------------------------------------
emails_to_send() -> emails_to_send() ->
mnesia:activity( mnesia:activity(
transaction, transaction,