-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from uclouvain/technical/OSIS-8748
[OSIS-8748] Better manage the errors when sending the emails
- Loading branch information
Showing
7 changed files
with
120 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# ############################################################################## | ||
# | ||
# OSIS stands for Open Student Information System. It's an application | ||
# designed to manage the core business of higher education institutions, | ||
# such as universities, faculties, institutes and professional schools. | ||
# The core business involves the administration of students, teachers, | ||
# courses, programs and so on. | ||
# | ||
# Copyright (C) 2015-2023 Université catholique de Louvain (http://www.uclouvain.be) | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# A copy of this license - GNU General Public License - is available | ||
# at the root of the source code of this program. If not, | ||
# see http://www.gnu.org/licenses/. | ||
# | ||
# ############################################################################## | ||
import uuid | ||
from typing import Dict | ||
|
||
|
||
class EmailNotificationSendingException(Exception): | ||
def __init__(self, exceptions: Dict[uuid.UUID, Exception]): | ||
message = ( | ||
'An error occurred while sending the email notifications:' | ||
if len(exceptions) == 1 | ||
else 'Errors occurred while sending the email notifications:' | ||
) | ||
|
||
for id_notification, exception in exceptions.items(): | ||
message += f'\n{id_notification}: {exception}.' | ||
|
||
super().__init__(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
osis_notification/management/commands/send_email_notifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from osis_notification.contrib.handlers import EmailNotificationHandler | ||
from osis_notification.contrib.exceptions import EmailNotificationSendingException | ||
from osis_notification.models import EmailNotification | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Send all the email notifications." | ||
|
||
def handle(self, *args, **options): | ||
exceptions = {} | ||
|
||
for notification in EmailNotification.objects.pending(): | ||
EmailNotificationHandler.process(notification) | ||
try: | ||
EmailNotificationHandler.process(notification) | ||
except Exception as exception: | ||
exceptions[notification.uuid] = exception | ||
|
||
if exceptions: | ||
raise EmailNotificationSendingException(exceptions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters