Log notifications at the time of sending
This commit is contained in:
parent
9399b34a56
commit
d8e75668b0
@ -250,7 +250,7 @@ def make_mailer(app):
|
||||
|
||||
|
||||
def make_notification_sender(app):
|
||||
app.notification_sender = NotificationSender(queue, app.logger)
|
||||
app.notification_sender = NotificationSender(queue)
|
||||
|
||||
|
||||
def apply_json_logger():
|
||||
|
@ -31,7 +31,7 @@ class ATSTQueue(RQ):
|
||||
self._queue_job(ATSTQueue._send_mail, recipients, subject, body)
|
||||
|
||||
def send_notification_mail(self, recipients, subject, body):
|
||||
self._queue_job(ATSTQueue._send_mail, recipients, subject, body)
|
||||
self._queue_job(ATSTQueue._send_notification_mail, recipients, subject, body)
|
||||
|
||||
# pylint: disable=pointless-string-statement
|
||||
"""Class methods to actually perform the work.
|
||||
@ -44,5 +44,14 @@ class ATSTQueue(RQ):
|
||||
def _send_mail(self, recipients, subject, body):
|
||||
app.mailer.send(recipients, subject, body)
|
||||
|
||||
@classmethod
|
||||
def _send_notification_mail(self, recipients, subject, body):
|
||||
app.logger.info(
|
||||
"Sending a notification to these recipients: {}\n\n{}".format(
|
||||
recipients, body
|
||||
)
|
||||
)
|
||||
app.mailer.send(recipients, subject, body)
|
||||
|
||||
|
||||
queue = ATSTQueue()
|
||||
|
@ -1,4 +1,3 @@
|
||||
from logging import Logger
|
||||
from sqlalchemy import select
|
||||
|
||||
from atst.queue import ATSTQueue
|
||||
@ -9,17 +8,11 @@ from atst.models import NotificationRecipient
|
||||
class NotificationSender(object):
|
||||
EMAIL_SUBJECT = "ATST notification"
|
||||
|
||||
def __init__(self, queue: ATSTQueue, logger: Logger):
|
||||
def __init__(self, queue: ATSTQueue):
|
||||
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_notification_mail(recipients, self.EMAIL_SUBJECT, body)
|
||||
|
||||
def _get_recipients(self, type_):
|
||||
|
@ -11,8 +11,8 @@ def mock_queue(queue):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def notification_sender(mock_queue, mock_logger):
|
||||
return NotificationSender(mock_queue, mock_logger)
|
||||
def notification_sender(mock_queue):
|
||||
return NotificationSender(mock_queue)
|
||||
|
||||
|
||||
def test_can_send_notification(mock_queue, notification_sender):
|
||||
|
Loading…
x
Reference in New Issue
Block a user