Add queue details
This commit is contained in:
parent
c80d15cfe8
commit
1517c9c071
|
@ -17,7 +17,7 @@
|
|||
|
||||
%% API
|
||||
-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
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
|
@ -49,6 +49,16 @@ start_link() ->
|
|||
queue() ->
|
||||
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
|
||||
%% Delete all the mails from the queue.
|
||||
|
@ -113,6 +123,9 @@ init([]) ->
|
|||
handle_call({queue_count}, _From, State) ->
|
||||
Count = length(emails_to_send()),
|
||||
{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) ->
|
||||
remove_all_emails(),
|
||||
{reply, ok, State};
|
||||
|
@ -203,6 +216,33 @@ code_change(_OldVsn, State, _Extra) ->
|
|||
%%%===================================================================
|
||||
%%% 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() ->
|
||||
mnesia:activity(
|
||||
transaction,
|
||||
|
|
Loading…
Reference in New Issue
Block a user