Nicely handle the case where we cannot connect to Redis
This commit is contained in:
parent
b252520ab0
commit
16d3ddd8cc
3 changed files with 17 additions and 4 deletions
|
@ -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
|
||||
|
|
Reference in a new issue