1
0
Fork 0
forked from s3lph/matemat

Added log output to receipt generation function.

This commit is contained in:
s3lph 2018-09-09 03:09:26 +02:00
parent fecaf55b2b
commit 2161ff79d9
2 changed files with 8 additions and 1 deletions

View file

@ -320,6 +320,7 @@ class MatematWebserver(object):
_PAGELET_CRON_STATIC_EVENT.set() _PAGELET_CRON_STATIC_EVENT.set()
def _cron_runner(self, fun: Callable[[Dict[str, str], jinja2.Environment, logging.Logger], None]): 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, fun(self._httpd.pagelet_variables,
self._httpd.jinja_env, self._httpd.jinja_env,
self._httpd.logger) self._httpd.logger)

View file

@ -20,16 +20,22 @@ def receipt_smtp_cron(config: Dict[str, str],
if config['SmtpSendReceipts'] != '1': if config['SmtpSendReceipts'] != '1':
# Sending receipts via mail is disabled # Sending receipts via mail is disabled
return return
logger.info('Searching users due for receipts.')
receipts: List[Receipt] = [] receipts: List[Receipt] = []
# Connect to the database # Connect to the database
with MatematDatabase(config['DatabaseFile']) as db: with MatematDatabase(config['DatabaseFile']) as db:
users: List[User] = db.list_users() users: List[User] = db.list_users()
for user in 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): if db.check_receipt_due(user):
logger.info('Generating receipt for user "%s".', user.name)
# Generate receipts that are due # Generate receipts that are due
receipt: Receipt = db.create_receipt(user, write=True) receipt: Receipt = db.create_receipt(user, write=True)
receipts.append(receipt) 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: if len(receipts) > 0:
_send_receipt_mails(receipts, jinja_env, logger, config) _send_receipt_mails(receipts, jinja_env, logger, config)