summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/notification/tasks.py
diff options
context:
space:
mode:
authorJack Morgan <jack.morgan@intel.com>2016-09-21 15:48:38 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-09-21 15:48:38 +0000
commitdcc6fa43043c685b7443cbc27da12ad9bf2225c4 (patch)
tree7927874aa51afd638e69f46d773e1c0b09d40f6b /tools/pharos-dashboard/notification/tasks.py
parent47f2f0a3224b8c990d5b9ab6c9628f9d7cf231b8 (diff)
parent3c8baae57206988fbdfc2d858ddc3f134e552f07 (diff)
Merge changes from topic 'pharos-dashboard'
* changes: Add a REST API for the dashboard Send notifications for booking start and end
Diffstat (limited to 'tools/pharos-dashboard/notification/tasks.py')
-rw-r--r--tools/pharos-dashboard/notification/tasks.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/pharos-dashboard/notification/tasks.py b/tools/pharos-dashboard/notification/tasks.py
new file mode 100644
index 00000000..ab3bddc7
--- /dev/null
+++ b/tools/pharos-dashboard/notification/tasks.py
@@ -0,0 +1,23 @@
+from celery import shared_task
+from datetime import timedelta
+
+from django.conf import settings
+from django.utils import timezone
+
+from notification.models import BookingNotification
+from notification_framework.notification import Notification
+
+
+@shared_task
+def send_booking_notifications():
+ messaging = Notification(dashboard_url=settings.RABBITMQ_URL)
+
+ now = timezone.now()
+ notifications = BookingNotification.objects.filter(submitted=False,
+ submit_time__gt=now,
+ submit_time__lt=now + timedelta(minutes=5))
+ for notification in notifications:
+ messaging.send(notification.type, notification.booking.resource.name,
+ notification.get_content())
+ notification.submitted = True
+ notification.save()