Add a better redis health check that reads and writes

This will hopefully catch issues earlier with Redis
This commit is contained in:
Joseph Schorr 2015-09-30 15:23:19 -04:00
parent 1b7449188b
commit 6e0ca735a5

View file

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