aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard
diff options
context:
space:
mode:
Diffstat (limited to 'src/dashboard')
-rw-r--r--src/dashboard/tasks.py6
-rw-r--r--src/dashboard/utils.py10
2 files changed, 14 insertions, 2 deletions
diff --git a/src/dashboard/tasks.py b/src/dashboard/tasks.py
index 3f88449..93e6a22 100644
--- a/src/dashboard/tasks.py
+++ b/src/dashboard/tasks.py
@@ -81,11 +81,15 @@ def free_hosts():
).filter(
end__lt=timezone.now(),
job__complete=True,
- resource__isnull=False
+ complete=False,
+ resource__isnull=False,
)
for booking in bookings:
ResourceManager.getInstance().releaseResourceBundle(booking.resource)
+ booking.complete = True
+ print("Booking", booking.id, "is now completed")
+ booking.save()
@shared_task
diff --git a/src/dashboard/utils.py b/src/dashboard/utils.py
index d6b697a..97c9ac7 100644
--- a/src/dashboard/utils.py
+++ b/src/dashboard/utils.py
@@ -7,7 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from django.core.exceptions import ObjectDoesNotExist
+from django.core.exceptions import (ObjectDoesNotExist, MultipleObjectsReturned)
class AbstractModelQuery():
@@ -38,7 +38,15 @@ class AbstractModelQuery():
@classmethod
def get(cls, *args, **kwargs):
+ """
+ Gets a single matching resource
+ Throws ObjectDoesNotExist if none found matching, or MultipleObjectsReturned if
+ the query does not narrow to a single object
+ """
try:
+ ls = cls.filter(*args, **kwargs)
+ if len(ls) > 1:
+ raise MultipleObjectsReturned()
return cls.filter(*args, **kwargs)[0]
except IndexError:
raise ObjectDoesNotExist()