diff options
author | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2020-11-09 21:57:49 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2020-11-09 21:57:49 +0000 |
commit | 6e7d8af810619e7ea3d14a612c735892c5ff1a84 (patch) | |
tree | c4c7723c3c392137a1875e5c29ec37662ba93e52 /src/notifier/manager.py | |
parent | 986f474e540669fd9fb72810b3f31fa3f4c3e97a (diff) | |
parent | 0d20968698aa4a5fc58bad9ae30857df504e170c (diff) |
Merge "Make emails send asynchronously (using celery job)"
Diffstat (limited to 'src/notifier/manager.py')
-rw-r--r-- | src/notifier/manager.py | 29 |
1 files changed, 5 insertions, 24 deletions
diff --git a/src/notifier/manager.py b/src/notifier/manager.py index 8ea8021..e2afdec 100644 --- a/src/notifier/manager.py +++ b/src/notifier/manager.py @@ -8,9 +8,8 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import os -from notifier.models import Notification, Emailed +from notifier.models import Notification, Emailed, Email -from django.core.mail import send_mail from django.template.loader import render_to_string from django.utils import timezone @@ -99,14 +98,8 @@ class NotificationHandler(object): # render email template message = render_to_string(template_name, context) - # finally, send the email - send_mail( - "Your Booking is Ready", - message, - os.environ.get("DEFAULT_FROM_EMAIL", "opnfv@laas-dashboard"), - [user.userprofile.email_addr], - fail_silently=False - ) + # finally, queue email for sending + Email.objects.create(title="Your Booking is Ready", message=message, recipient=user.userprofile.email_addr) @classmethod def email_booking_over(cls, booking): @@ -124,13 +117,7 @@ class NotificationHandler(object): message = render_to_string(template_name, context) - send_mail( - "Your Booking has Expired", - message, - os.environ.get("DEFAULT_FROM_EMAIL", "opnfv@laas-dashboard"), - [user.userprofile.email_addr], - fail_silently=False - ) + Email.objects.create(title="Your Booking has Expired", message=message, recipient=user.userprofile.email_addr) @classmethod def email_booking_expiring(cls, booking): @@ -148,13 +135,7 @@ class NotificationHandler(object): message = render_to_string(template_name, context) - send_mail( - "Your Booking is Expiring", - message, - os.environ.get("DEFAULT_FROM_EMAIL", "opnfv@laas-dashboard"), - [user.userprofile.email_addr], - fail_silently=False - ) + Email.objects.create(title="Your Booking is Expiring", message=message, recipient=user.userprofile.email_addr) @classmethod def task_updated(cls, task): |