From 16d3ddd8ccece58eb981ce2d7bd2f02b66353e64 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 25 Mar 2014 13:29:06 -0400 Subject: [PATCH] Nicely handle the case where we cannot connect to Redis --- data/buildlogs.py | 15 +++++++++++---- endpoints/api.py | 2 ++ static/js/app.js | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/data/buildlogs.py b/data/buildlogs.py index bb96ac7dc..817fbc2b4 100644 --- a/data/buildlogs.py +++ b/data/buildlogs.py @@ -40,9 +40,12 @@ class BuildLogs(object): Returns a tuple of the current length of the list and an iterable of the requested log entries. """ - llen = self._redis.llen(self._logs_key(build_id)) - log_entries = self._redis.lrange(self._logs_key(build_id), start_index, -1) - return (llen, (json.loads(entry) for entry in log_entries)) + try: + llen = self._redis.llen(self._logs_key(build_id)) + log_entries = self._redis.lrange(self._logs_key(build_id), start_index, -1) + return (llen, (json.loads(entry) for entry in log_entries)) + except redis.ConnectionError: + return (0, []) @staticmethod def _status_key(build_id): @@ -59,5 +62,9 @@ class BuildLogs(object): """ Loads the status information for the specified build id. """ - fetched = self._redis.get(self._status_key(build_id)) + try: + fetched = self._redis.get(self._status_key(build_id)) + except redis.ConnectionError: + return None + return json.loads(fetched) if fetched else None diff --git a/endpoints/api.py b/endpoints/api.py index 5c86e8710..c6bd504a3 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -1160,6 +1160,8 @@ def get_job_config(build_obj): def build_status_view(build_obj, can_write=False): status = build_logs.get_status(build_obj.uuid) + if not status: + status = 'cannot_load' return { 'id': build_obj.uuid, diff --git a/static/js/app.js b/static/js/app.js index 57ef53b29..674b52e33 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -3365,6 +3365,9 @@ quayApp.directive('buildMessage', function () { controller: function($scope, $element) { $scope.getBuildMessage = function (phase) { switch (phase) { + case 'cannot_load': + return 'Cannot load build status - Please report this error'; + case 'starting': case 'initializing': return 'Starting Dockerfile build'; @@ -3419,6 +3422,7 @@ quayApp.directive('buildProgress', function () { case 'initializing': case 'starting': case 'waiting': + case 'cannot_load': return 0; break; }