From 269813aa18b05c104a14dfb2295a0b66c877f604 Mon Sep 17 00:00:00 2001 From: Fabio Salvini Date: Fri, 27 Oct 2017 21:58:25 +0200 Subject: [PATCH] Add function to delete all the emails in the queue --- apps/log_monitor/src/mailer.erl | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/log_monitor/src/mailer.erl b/apps/log_monitor/src/mailer.erl index 272e46c..5db9ec8 100644 --- a/apps/log_monitor/src/mailer.erl +++ b/apps/log_monitor/src/mailer.erl @@ -17,7 +17,7 @@ %% API -export([start_link/0]). --export([queue/0]). +-export([queue/0, empty_queue/0]). %% 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 +%% Delete all the mails from the queue. +%% +%% @spec empty_queue() -> ok +%% @end +%%-------------------------------------------------------------------- +empty_queue() -> + gen_server:call(mailer, {empty_queue}). + %%%=================================================================== %%% gen_server callbacks %%%=================================================================== @@ -93,7 +103,9 @@ init([]) -> handle_call({queue_count}, _From, State) -> Count = length(emails_to_send()), {reply, Count, State}; - +handle_call({empty_queue}, _From, State) -> + remove_all_emails(), + {reply, ok, State}; handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}. @@ -266,6 +278,18 @@ remove_email(Id) -> end), 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 %% @doc