Add a better redis health check that reads and writes
This will hopefully catch issues earlier with Redis
This commit is contained in:
parent
1b7449188b
commit
6e0ca735a5
1 changed files with 13 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
import redis
|
import redis
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
from util.dynamic import import_class
|
from util.dynamic import import_class
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
@ -65,7 +66,6 @@ class RedisBuildLogs(object):
|
||||||
"""
|
"""
|
||||||
self._redis.expire(self._logs_key(build_id), ONE_DAY)
|
self._redis.expire(self._logs_key(build_id), ONE_DAY)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _status_key(build_id):
|
def _status_key(build_id):
|
||||||
return 'builds/%s/status' % build_id
|
return 'builds/%s/status' % build_id
|
||||||
|
@ -88,9 +88,20 @@ class RedisBuildLogs(object):
|
||||||
|
|
||||||
return json.loads(fetched) if fetched else None
|
return json.loads(fetched) if fetched else None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _health_key():
|
||||||
|
return '_health'
|
||||||
|
|
||||||
def check_health(self):
|
def check_health(self):
|
||||||
try:
|
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:
|
except redis.ConnectionError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Reference in a new issue