summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Price <brian.price@badcure.com>2018-11-29 00:38:52 -0600
committerAsif Saif Uddin <auvipy@gmail.com>2018-11-29 12:38:52 +0600
commita59b44e9fb8d00758dd6a3c560e2f158e672580d (patch)
treed09c890b59d545a14889f31719eb01dbf5d33b20
parent01ab1a7f5981caa7ceac99f500f20261ffb75b7c (diff)
downloadkombu-a59b44e9fb8d00758dd6a3c560e2f158e672580d.tar.gz
Moving the handling of Sentinel failures to the redis library itself. (#813)
* Moving the handling of Sentinel failures to the redis library itself. Currently Celery dies if the first Sentinel servive on the list is down, as in if you lose a machine. * Removing the use of unittest. * Changing how an empty list is defined.
-rw-r--r--kombu/transport/redis.py13
-rw-r--r--t/unit/transport/test_redis.py9
2 files changed, 14 insertions, 8 deletions
diff --git a/kombu/transport/redis.py b/kombu/transport/redis.py
index f747d714..3e34fb2d 100644
--- a/kombu/transport/redis.py
+++ b/kombu/transport/redis.py
@@ -1076,9 +1076,7 @@ class SentinelChannel(Channel):
sentinel://0.0.0.0:26379;sentinel://0.0.0.0:26380/...
- where each sentinel is separated by a `;`. Multiple sentinels are handled
- by :class:`kombu.Connection` constructor, and placed in the alternative
- list of servers to connect to in case of connection failure.
+ where each sentinel is separated by a `;`.
Other arguments for the sentinel should come from the transport options
(see :method:`Celery.connection` which is in charge of creating the
@@ -1102,11 +1100,14 @@ class SentinelChannel(Channel):
additional_params.pop('host', None)
additional_params.pop('port', None)
-
+ connection_list = []
+ for url in self.connection.client.alt:
+ if url and 'sentinel://' in url:
+ connection_list.append(url.split('/')[2].split(':'))
sentinel_inst = sentinel.Sentinel(
- [(connparams['host'], connparams['port'])],
+ connection_list,
min_other_sentinels=getattr(self, 'min_other_sentinels', 0),
- sentinel_kwargs=getattr(self, 'sentinel_kwargs', {}),
+ sentinel_kwargs=getattr(self, 'sentinel_kwargs',None),
**additional_params)
master_name = getattr(self, 'master_name', None)
diff --git a/t/unit/transport/test_redis.py b/t/unit/transport/test_redis.py
index d15de986..1fded97a 100644
--- a/t/unit/transport/test_redis.py
+++ b/t/unit/transport/test_redis.py
@@ -1344,14 +1344,19 @@ class test_RedisSentinel:
def test_getting_master_from_sentinel(self):
with patch('redis.sentinel.Sentinel') as patched:
connection = Connection(
- 'sentinel://localhost:65534/',
+ 'sentinel://localhost:65534/;sentinel://localhost:65535/;sentinel://localhost:65536/;',
transport_options={
'master_name': 'not_important',
},
)
connection.channel()
- assert patched
+ patched.assert_called_once_with(
+ [[u'localhost', u'65534'], [u'localhost', u'65535'], [u'localhost', u'65536']],
+ connection_class=mock.ANY, db=0, max_connections=10,
+ min_other_sentinels=0, password=None, sentinel_kwargs=None,
+ socket_connect_timeout=None, socket_keepalive=None,
+ socket_keepalive_options=None, socket_timeout=None)
master_for = patched.return_value.master_for
master_for.assert_called()