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