aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard/tasks.py
blob: ac4b0062de7bdac20eb87a27c7c47fb21bbf8f69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
##############################################################################
# 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 booking.models import Booking
from celery import shared_task
from django.utils import timezone
from api.views import liblaas_end_booking

# todo - make a task to check for expired bookings
@shared_task
def end_expired_bookings():
    print("Celery task for end_expired_bookings() has been triggered")
    cleanup_set = Booking.objects.filter(end__lte=timezone.now(), ).filter(complete=False)
    print("Newly expired bookings: ", cleanup_set)
    for booking in cleanup_set:
        booking.complete = True
        if (booking.aggregateId):
            print("ending booking " + str(booking.id) + " with agg id: ", booking.aggregateId)
            liblaas_end_booking(booking.aggregateId)
        else:
            print("booking " + str(booking.id) + " has no agg id")
        booking.save()
    print("Finished end_expired_bookings()")