From 795de4235d3b0df05be4658871744ef2e4e0c0a1 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 28 Mar 2014 14:20:06 -0400 Subject: [PATCH] Change "cannot connect to redid" to be a raised exception --- data/buildlogs.py | 6 ++++-- endpoints/api/build.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/data/buildlogs.py b/data/buildlogs.py index 817fbc2b4..43723e211 100644 --- a/data/buildlogs.py +++ b/data/buildlogs.py @@ -1,6 +1,8 @@ import redis import json +class BuildStatusRetrievalError(Exception): + pass class BuildLogs(object): ERROR = 'error' @@ -45,7 +47,7 @@ class BuildLogs(object): 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, []) + raise BuildStatusRetrievalError('Cannot retrieve build logs') @staticmethod def _status_key(build_id): @@ -65,6 +67,6 @@ class BuildLogs(object): try: fetched = self._redis.get(self._status_key(build_id)) except redis.ConnectionError: - return None + raise BuildStatusRetrievalError('Cannot retrieve build status') return json.loads(fetched) if fetched else None diff --git a/endpoints/api/build.py b/endpoints/api/build.py index f14d097bb..0e3ef76e7 100644 --- a/endpoints/api/build.py +++ b/endpoints/api/build.py @@ -11,6 +11,7 @@ from endpoints.common import start_build from endpoints.trigger import BuildTrigger from data import model from auth.permissions import ModifyRepositoryPermission +from data.buildlogs import BuildStatusRetrievalError logger = logging.getLogger(__name__) @@ -48,7 +49,11 @@ def trigger_view(trigger): def build_status_view(build_obj, can_write=False): - status = build_logs.get_status(build_obj.uuid) + try: + status = build_logs.get_status(build_obj.uuid) + except BuildStatusRetrievalError: + status = None + logger.debug('Can write: %s job_config: %s', can_write, build_obj.job_config) resp = { 'id': build_obj.uuid, @@ -169,7 +174,10 @@ class RepositoryBuildLogs(RepositoryParamResource): start = int(request.args.get('start', 0)) - count, logs = build_logs.get_log_entries(build.uuid, start) + try: + count, logs = build_logs.get_log_entries(build.uuid, start) + except BuildStatusRetrievalError: + count, logs = (0, []) response_obj.update({ 'start': start,