From c5214f6accee741d64efd29498d813aae9f4068e Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Tue, 6 Mar 2018 12:07:05 -0500 Subject: Gracefully Handle Missing Jenkins Utilization for Dev Pod Jira: PHAROS-364 Change-Id: I0641c658914e600672151d7c0d1661acba794f0f Signed-off-by: Sawyer Bergeron --- src/dashboard/views.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/dashboard/views.py b/src/dashboard/views.py index 62a9f83..4bab036 100644 --- a/src/dashboard/views.py +++ b/src/dashboard/views.py @@ -120,22 +120,27 @@ class JenkinsUtilizationJSON(View): def get(self, request, *args, **kwargs): resource = get_object_or_404(Resource, id=kwargs['resource_id']) weeks = int(kwargs['weeks']) - utilization = resource.slave.get_utilization(timedelta(weeks=weeks)) - utilization = [ - { - 'label': 'Offline', - 'data': utilization['offline'], - 'color': '#d9534f' - }, - { - 'label': 'Online', - 'data': utilization['online'], - 'color': '#5cb85c' - }, - { - 'label': 'Idle', - 'data': utilization['idle'], - 'color': '#5bc0de' - }, - ] - return JsonResponse({'data': utilization}) + try: + utilization = resource.slave.get_utilization(timedelta(weeks=weeks)) + utilization = [ + { + 'label': 'Offline', + 'data': utilization['offline'], + 'color': '#d9534f' + }, + { + 'label': 'Online', + 'data': utilization['online'], + 'color': '#5cb85c' + }, + { + 'label': 'Idle', + 'data': utilization['idle'], + 'color': '#5bc0de' + }, + ] + jutilization = JsonResponse({'data': utilization}) + except AttributeError: + return JsonResponse({'data': ''}) + if jutilization: + return jutilization -- cgit 1.2.3-korg