More idiomatic initialization of notification_sender
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user