aboutsummaryrefslogtreecommitdiffstats
path: root/src/notifier/tasks.py
diff options
context:
space:
mode:
authorBrandon Lo <lobrandon1217@gmail.com>2019-11-26 16:39:26 -0500
committerBrandon Lo <lobrandon1217@gmail.com>2019-12-03 15:16:16 -0500
commit6be40a5f2d75b157cf2a2374f2f866f6fdc92b18 (patch)
treebdfa3b9ed77ebfef33f58262950ad551d579e3bb /src/notifier/tasks.py
parentf1d7b9300fbb06495c6087f975cdbb68a894da37 (diff)
Add warning email and notification
This adds the abandoned changes made to the notification system and also adds a simple task to check for expiring bookings and sends out emails and notifications. Change-Id: I1530d19f41cf93626bb642e6b269f9ec55860b81 Signed-off-by: Brandon Lo <lobrandon1217@gmail.com>
Diffstat (limited to 'src/notifier/tasks.py')
-rw-r--r--src/notifier/tasks.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/notifier/tasks.py b/src/notifier/tasks.py
new file mode 100644
index 0000000..b45ab8e
--- /dev/null
+++ b/src/notifier/tasks.py
@@ -0,0 +1,35 @@
+##############################################################################
+# Copyright (c) 2016 Max Breitenfeldt and others.
+# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+
+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.manager import NotificationHandler
+
+
+@shared_task
+def notify_expiring():
+ """
+ Notify users if their booking is within 48 hours of expiring.
+ """
+ expire_time = timezone.now() + timezone.timedelta(hours=settings.EXPIRE_HOURS)
+ # Don't email people about bookings that have started recently
+ start_time = timezone.now() - timezone.timedelta(hours=settings.EXPIRE_LIFETIME)
+ bookings = Booking.objects.filter(end__lte=expire_time,
+ end__gte=timezone.now(),
+ start__lte=start_time)
+ for booking in bookings:
+ if Emailed.objects.filter(almost_end_booking=booking).exists():
+ continue
+ NotificationHandler.notify_booking_expiring(booking)
+ Emailed.objects.create(almost_end_booking=booking)