I hate Redis!
- Remove redis check from our health endpoint in prod entirely - Have the redis check have a maximum timeout of 1 second
This commit is contained in:
parent
ad53bf5671
commit
c518874ded
3 changed files with 22 additions and 10 deletions
|
@ -18,7 +18,11 @@ class RedisBuildLogs(object):
|
|||
PHASE = 'phase'
|
||||
|
||||
def __init__(self, redis_config):
|
||||
self._redis = redis.StrictRedis(socket_connect_timeout=5, **redis_config)
|
||||
args = dict(redis_config)
|
||||
args.update({'socket_connect_timeout': 5})
|
||||
|
||||
self._redis_config = redis_config
|
||||
self._redis = redis.StrictRedis(**args)
|
||||
|
||||
@staticmethod
|
||||
def _logs_key(build_id):
|
||||
|
@ -94,12 +98,16 @@ class RedisBuildLogs(object):
|
|||
|
||||
def check_health(self):
|
||||
try:
|
||||
if not self._redis.ping() == True:
|
||||
args = dict(self._redis_config)
|
||||
args.update({'socket_connect_timeout': 1, 'socket_timeout': 1})
|
||||
|
||||
connection = redis.StrictRedis(**args)
|
||||
if not connection.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())
|
||||
connection.set(self._health_key(), time.time())
|
||||
connection.get(self._health_key())
|
||||
|
||||
return True
|
||||
except redis.ConnectionError:
|
||||
|
|
Reference in a new issue