From b9a57d0054e255029cd26072f89729bda6f6b43e Mon Sep 17 00:00:00 2001 From: Fabio Salvini Date: Wed, 25 Oct 2017 04:34:41 +0200 Subject: [PATCH] Email queue count --- apps/log_monitor/src/mailer.erl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/log_monitor/src/mailer.erl b/apps/log_monitor/src/mailer.erl index c9b5d31..8e1aa75 100644 --- a/apps/log_monitor/src/mailer.erl +++ b/apps/log_monitor/src/mailer.erl @@ -17,6 +17,7 @@ %% API -export([start_link/0]). +-export([queue/0]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, @@ -38,6 +39,16 @@ start_link() -> gen_server:start_link(?MODULE, [], []). +%%-------------------------------------------------------------------- +%% @doc +%% Get the number of emails to send. +%% +%% @spec queue() -> {ok, Count} +%% @end +%%-------------------------------------------------------------------- +queue() -> + gen_server:call(mailer, {queue_count}). + %%%=================================================================== %%% gen_server callbacks %%%=================================================================== @@ -72,6 +83,10 @@ init([]) -> %% {stop, Reason, State} %% @end %%-------------------------------------------------------------------- +handle_call({queue_count}, _From, State) -> + Count = length(emails_to_send()), + {reply, Count, State}; + handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}.