diff --git a/data/buildlogs.py b/data/buildlogs.py index 17e5b397f..e9ea4a78f 100644 --- a/data/buildlogs.py +++ b/data/buildlogs.py @@ -1,5 +1,6 @@ import redis import json +import time from util.dynamic import import_class from datetime import timedelta @@ -65,7 +66,6 @@ class RedisBuildLogs(object): """ self._redis.expire(self._logs_key(build_id), ONE_DAY) - @staticmethod def _status_key(build_id): return 'builds/%s/status' % build_id @@ -88,9 +88,20 @@ class RedisBuildLogs(object): return json.loads(fetched) if fetched else None + @staticmethod + def _health_key(): + return '_health' + def check_health(self): try: - return self._redis.ping() == True + if not self._redis.ping() == True: + return False + + # Ensure we can write and read a key. + self._redis.set(self._health_key(), time.time()) + self._redis.get(self._health_key()) + + return True except redis.ConnectionError: return False