aboutsummaryrefslogtreecommitdiffstats
path: root/src/notifier/tasks.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2020-10-05 16:13:03 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2020-10-05 16:13:54 -0400
commit0d20968698aa4a5fc58bad9ae30857df504e170c (patch)
tree615e00ef5090accde08e913e431057e11cf706ea /src/notifier/tasks.py
parent836ba6a22ece7590c203c837669b73259f02540a (diff)
Make emails send asynchronously (using celery job)
Change-Id: I9f4d5d05a0b72c883d667cf3910b3b318cbe82fa Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/notifier/tasks.py')
-rw-r--r--src/notifier/tasks.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/notifier/tasks.py b/src/notifier/tasks.py
index 474d64d..389750a 100644
--- a/src/notifier/tasks.py
+++ b/src/notifier/tasks.py
@@ -13,8 +13,11 @@ from celery import shared_task
from django.utils import timezone
from django.conf import settings
from booking.models import Booking
-from notifier.models import Emailed
+from notifier.models import Emailed, Email
from notifier.manager import NotificationHandler
+from django.core.mail import send_mail
+
+import os
@shared_task
@@ -33,3 +36,16 @@ def notify_expiring():
continue
NotificationHandler.notify_booking_expiring(booking)
Emailed.objects.create(almost_end_booking=booking)
+
+
+@shared_task
+def dispatch_emails():
+ for email in Email.objects.filter(sent=False):
+ email.sent = True
+ email.save()
+ send_mail(
+ email.title,
+ email.message,
+ os.environ.get("DEFAULT_FROM_EMAIL", "opnfv@laas-dashboard"),
+ email.recipient,
+ fail_silently=False)