Restructure dashboard project for docker deploying
[pharos-tools.git] / pharos-dashboard / src / notification / tasks.py
1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10
11 from celery import shared_task
12 from datetime import timedelta
13
14 from django.conf import settings
15 from django.utils import timezone
16
17 from notification.models import BookingNotification
18 from notification_framework.notification import Notification
19
20
21 @shared_task
22 def send_booking_notifications():
23     messaging = Notification(dashboard_url=settings.RABBITMQ_URL)
24
25     now = timezone.now()
26     notifications = BookingNotification.objects.filter(submitted=False,
27                                                        submit_time__gt=now,
28                                                        submit_time__lt=now + timedelta(minutes=5))
29     for notification in notifications:
30         messaging.send(notification.type, notification.booking.resource.name,
31                        notification.get_content())
32         notification.submitted = True
33         notification.save()