Merge pull request #572 from coreos-inc/redishealthcheck

Add a better redis health check that reads and writes
This commit is contained in:
josephschorr 2015-09-30 15:41:00 -04:00
commit 6498e1fe87

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