Skip to content
Snippets Groups Projects
Commit f9e8c30d authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature DBOARD3-220-configurable-socket-timeout.

parents c4203334 63aa728e
No related branches found
No related tags found
No related merge requests found
......@@ -7,3 +7,4 @@ coverage.xml
.coverage
.tox
htmlcov
dist
......@@ -16,7 +16,11 @@ CONFIG_SCHEMA = {
},
"required": ["hostname", "dbname", "username", "password"],
"additionalProperties": False
},
"timeout": {
"type": "number",
"maximum": 10, # sanity
"exclusiveMinimum": 0
}
},
......@@ -37,7 +41,8 @@ CONFIG_SCHEMA = {
"type": "object",
"properties": {
"hostname": {"type": "string"},
"port": {"type": "integer"}
"port": {"type": "integer"},
"socket_timeout": {"$ref": "#/definitions/timeout"}
},
"required": ["hostname", "port"],
"additionalProperties": False
......@@ -47,7 +52,9 @@ CONFIG_SCHEMA = {
"properties": {
"hostname": {"type": "string"},
"port": {"type": "integer"},
"name": {"type": "string"}
"name": {"type": "string"},
"redis_socket_timeout": {"$ref": "#/definitions/timeout"},
"sentinel_socket_timeout": {"$ref": "#/definitions/timeout"}
},
"required": ["hostname", "port", "name"],
"additionalProperties": False
......
......@@ -7,6 +7,9 @@ import redis.sentinel
logger = logging.getLogger(__name__)
DEFAULT_REDIS_SENTINEL_TIMEOUT = 0.1
DEFAULT_SENTINEL_SOCKET_TIMEOUT = 0.1
DB_LATCH_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
......@@ -102,19 +105,23 @@ def _get_redis(config, dbid=None):
dbid = min(config['redis-databases'])
kwargs = {
'db': dbid,
'socket_timeout': 0.1
'db': dbid
}
if 'sentinel' in config:
kwargs['socket_timeout'] = config['sentinel'].get(
'sentinel_socket_timeout', DEFAULT_SENTINEL_SOCKET_TIMEOUT)
sentinel = redis.sentinel.Sentinel([(
config['sentinel']['hostname'],
config['sentinel']['port'])],
**kwargs)
return sentinel.master_for(
config['sentinel']['name'],
socket_timeout=0.1)
socket_timeout=config['sentinel'].get(
'redis_socket_timeout', DEFAULT_REDIS_SENTINEL_TIMEOUT))
else:
kwargs['socket_timeout'] = config['redis'].get(
'socket_timeout', DEFAULT_REDIS_SENTINEL_TIMEOUT)
return redis.StrictRedis(
host=config['redis']['hostname'],
port=config['redis']['port'],
......
......@@ -13,7 +13,7 @@ setup(
'click',
'mysql-connector',
'pysnmp',
'jsonschema',
'jsonschema==3.2.0',
'paramiko',
'flask',
'redis==3.2.1',
......
......@@ -38,7 +38,8 @@ def data_config_filename():
},
"redis": {
"hostname": "xxxxxx",
"port": 6379
"port": 6379,
"socket_timeout": 2.8
},
"redis-databases": [0, 7],
"junosspace": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment