From b3fb2b3cad93a2d8e836d37bfb37064429e37897 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Fri, 3 Jan 2020 08:59:15 +0100
Subject: [PATCH] use new socket timeout params for redis/sentinel connections

---
 inventory_provider/tasks/common.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/inventory_provider/tasks/common.py b/inventory_provider/tasks/common.py
index f4492f61..3a474c8e 100644
--- a/inventory_provider/tasks/common.py
+++ b/inventory_provider/tasks/common.py
@@ -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'],
-- 
GitLab