Add function to delete all the emails in the queue

This commit is contained in:
Fabio Salvini 2017-10-27 21:58:25 +02:00
parent 5e2462b7b2
commit 269813aa18

View File

@ -17,7 +17,7 @@
%% API %% API
-export([start_link/0]). -export([start_link/0]).
-export([queue/0]). -export([queue/0, empty_queue/0]).
%% 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
%% Delete all the mails from the queue.
%%
%% @spec empty_queue() -> ok
%% @end
%%--------------------------------------------------------------------
empty_queue() ->
gen_server:call(mailer, {empty_queue}).
%%%=================================================================== %%%===================================================================
%%% gen_server callbacks %%% gen_server callbacks
%%%=================================================================== %%%===================================================================
@ -93,7 +103,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({empty_queue}, _From, State) ->
remove_all_emails(),
{reply, ok, State};
handle_call(_Request, _From, State) -> handle_call(_Request, _From, State) ->
Reply = ok, Reply = ok,
{reply, Reply, State}. {reply, Reply, State}.
@ -266,6 +278,18 @@ remove_email(Id) ->
end), end),
ok. ok.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Remove all emails from the database.
%%
%% @spec remove_all_emails() -> void()
%% @end
%%--------------------------------------------------------------------
remove_all_emails() ->
mnesia:clear_table(log_monitor_error),
ok.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @private %% @private
%% @doc %% @doc