aboutsummaryrefslogtreecommitdiffstats
path: root/src/notifier/tasks.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2020-11-09 21:57:49 +0000
committerGerrit Code Review <gerrit@opnfv.org>2020-11-09 21:57:49 +0000
commit6e7d8af810619e7ea3d14a612c735892c5ff1a84 (patch)
treec4c7723c3c392137a1875e5c29ec37662ba93e52 /src/notifier/tasks.py
parent986f474e540669fd9fb72810b3f31fa3f4c3e97a (diff)
parent0d20968698aa4a5fc58bad9ae30857df504e170c (diff)
Merge "Make emails send asynchronously (using celery job)"
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)