Nicely handle the case where we cannot connect to Redis

This commit is contained in:
Joseph Schorr 2014-03-25 13:29:06 -04:00
parent b252520ab0
commit 16d3ddd8cc
3 changed files with 17 additions and 4 deletions

View file

@ -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

View file

@ -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,

View file

@ -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;
}