More idiomatic initialization of notification_sender

This commit is contained in:
richard-dds
2019-05-13 12:06:33 -04:00
parent aaa9d47ccf
commit c03b69b351
3 changed files with 15 additions and 7 deletions

View File

@@ -1,4 +1,6 @@
from atst.queue import ATSTQueue, queue
from logging import Logger
from atst.queue import ATSTQueue
from atst.database import db
from atst.models import NotificationRecipient
@@ -6,11 +8,14 @@ from atst.models import NotificationRecipient
class NotificationSender(object):
EMAIL_SUBJECT = "ATST notification"
def __init__(self, queue: ATSTQueue):
def __init__(self, queue: ATSTQueue, logger: Logger):
self.queue = queue
self.logger = logger
def send(self, body, type_=None):
recipients = self._get_recipients(type_)
self.logger.info(
"Sending a notification to these recipients: {}\n\n{}".format(recipients, body))
self.queue.send_mail(recipients, self.EMAIL_SUBJECT, body)
def _get_recipients(self, type_):
@@ -18,6 +23,3 @@ class NotificationSender(object):
recipient.email
for recipient in db.session.query(NotificationRecipient).all()
]
notification_sender = NotificationSender(queue)