From 2161ff79d9831c3f0d4a3a2a46ca08893faeb311 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 9 Sep 2018 03:09:26 +0200 Subject: [PATCH] Added log output to receipt generation function. --- matemat/webserver/httpd.py | 1 + matemat/webserver/pagelets/receipt_smtp_cron.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/matemat/webserver/httpd.py b/matemat/webserver/httpd.py index 6f601fc..e5d1003 100644 --- a/matemat/webserver/httpd.py +++ b/matemat/webserver/httpd.py @@ -320,6 +320,7 @@ class MatematWebserver(object): _PAGELET_CRON_STATIC_EVENT.set() def _cron_runner(self, fun: Callable[[Dict[str, str], jinja2.Environment, logging.Logger], None]): + self._httpd.logger.info('Executing cron job "%s"', fun.__name__) fun(self._httpd.pagelet_variables, self._httpd.jinja_env, self._httpd.logger) diff --git a/matemat/webserver/pagelets/receipt_smtp_cron.py b/matemat/webserver/pagelets/receipt_smtp_cron.py index b9ceafe..0df5d77 100644 --- a/matemat/webserver/pagelets/receipt_smtp_cron.py +++ b/matemat/webserver/pagelets/receipt_smtp_cron.py @@ -20,16 +20,22 @@ def receipt_smtp_cron(config: Dict[str, str], if config['SmtpSendReceipts'] != '1': # Sending receipts via mail is disabled return + logger.info('Searching users due for receipts.') receipts: List[Receipt] = [] # Connect to the database with MatematDatabase(config['DatabaseFile']) as db: users: List[User] = db.list_users() for user in users: + if user.email is None: + logger.debug('User "%s" has no e-mail address.', user.name) if db.check_receipt_due(user): + logger.info('Generating receipt for user "%s".', user.name) # Generate receipts that are due receipt: Receipt = db.create_receipt(user, write=True) receipts.append(receipt) - # Send all generated receipts via e-mail + else: + logger.debug('No receipt due for user "%s".', user.name) + # Send all generated receipts via e-mailgi if len(receipts) > 0: _send_receipt_mails(receipts, jinja_env, logger, config)