summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/dashboard/views.py
diff options
context:
space:
mode:
authormaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:11:58 +0200
committermaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:11:58 +0200
commit66eb4d851e63d20031502ec0c96aaabe34c6fd32 (patch)
tree98248b6faf6b3c742efef258e34f06cc92d1a888 /tools/pharos-dashboard/dashboard/views.py
parent3b5ef3b0a88247eeafeee878de528aad71f9fd4b (diff)
Implement periodic tasks
JIRA: RELENG-12 The dashboard is now querying jenkins periodically and saving the results in the database. This fixes delays that were caused by calling the jenkins API. Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/dashboard/views.py')
-rw-r--r--tools/pharos-dashboard/dashboard/views.py38
1 files changed, 13 insertions, 25 deletions
diff --git a/tools/pharos-dashboard/dashboard/views.py b/tools/pharos-dashboard/dashboard/views.py
index ed62b356..a4c0c4e9 100644
--- a/tools/pharos-dashboard/dashboard/views.py
+++ b/tools/pharos-dashboard/dashboard/views.py
@@ -1,19 +1,18 @@
+from datetime import timedelta
from django.utils import timezone
from django.views.generic import TemplateView
from booking.models import Booking
from dashboard.models import Resource
from jenkins import adapter as jenkins
+from jenkins.models import JenkinsSlave, JenkinsStatistic
class JenkinsSlavesView(TemplateView):
template_name = "dashboard/jenkins_slaves.html"
def get_context_data(self, **kwargs):
- slaves = jenkins.get_all_slaves()
- for slave in slaves:
- jenkins.parse_slave_data(slave, slave)
-
+ slaves = JenkinsSlave.objects.all()
context = super(JenkinsSlavesView, self).get_context_data(**kwargs)
context.update({'title': "Jenkins Slaves", 'slaves': slaves})
return context
@@ -23,15 +22,7 @@ class CIPodsView(TemplateView):
template_name = "dashboard/ci_pods.html"
def get_context_data(self, **kwargs):
- resources = Resource.objects.filter().values() # get resources as a set of dicts
- ci_pods = []
- for resource in resources:
- if not jenkins.is_ci_slave(resource['slavename']):
- continue
- ci_slave = jenkins.get_slave(resource['slavename'])
- jenkins.parse_slave_data(resource, ci_slave)
- ci_pods.append(resource)
-
+ ci_pods = Resource.objects.filter(slave__ci_slave=True)
context = super(CIPodsView, self).get_context_data(**kwargs)
context.update({'title': "CI Pods", 'ci_pods': ci_pods})
return context
@@ -41,21 +32,18 @@ class DevelopmentPodsView(TemplateView):
template_name = "dashboard/dev_pods.html"
def get_context_data(self, **kwargs):
- resources = Resource.objects.filter().values() # get resources as a set of dicts
- dev_pods = []
+ resources = Resource.objects.filter(slave__dev_pod=True)
- current_bookings = Booking.objects.filter(start__lte=timezone.now())
- current_bookings = current_bookings.filter(end__gt=timezone.now())
+ bookings = Booking.objects.filter(start__lte=timezone.now())
+ bookings = bookings.filter(end__gt=timezone.now())
+ dev_pods = []
for resource in resources:
- if not jenkins.is_dev_pod(resource['slavename']):
- continue
- dev_pod = jenkins.get_slave(resource['slavename'])
- jenkins.parse_slave_data(resource, dev_pod)
- for booking in current_bookings:
- if booking.resource.slavename == resource['slavename']:
- resource['current_booking'] = booking
- dev_pods.append(resource)
+ dev_pod = (resource, None)
+ for booking in bookings:
+ if booking.resource == resource:
+ dev_pod = (resource, booking)
+ dev_pods.append(dev_pod)
context = super(DevelopmentPodsView, self).get_context_data(**kwargs)
context.update({'title': "Development Pods", 'dev_pods': dev_pods})