From 0f4da8d450d1a44558382c1858f025faea1b3fde Mon Sep 17 00:00:00 2001 From: Anthony Lukach Date: Wed, 2 Aug 2017 03:06:47 -0600 Subject: [PATCH] Pass connection options from broker_options to default_channel (#769) * Pass connection options from broker_options to default_channel (fixes #765) * Fixup * Fixup --- Changelog | 14 ++++++++++++++ kombu/connection.py | 14 +++++++++++++- t/unit/test_connection.py | 26 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 9fc5ca90..ca57deeb 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,20 @@ Change history ================ +.. _version-4.1.1: + +4.1.1 +===== +:release-date: TBD +:release-by: TBD + +- Now passing ``max_retries``, ``interval_start``, ``interval_step``, + ``interval_max`` parameters from broker ``transport_options`` to + :meth:`~kombu.Connection.ensure_connection` when returning + :meth:`~kombu.Connection.default_connection` (Issue #765). + + Contributed by **Anthony Lukach**. + .. _version-4.1.0: 4.1.0 diff --git a/kombu/connection.py b/kombu/connection.py index 3d452240..1f5dba7b 100644 --- a/kombu/connection.py +++ b/kombu/connection.py @@ -815,8 +815,20 @@ class Connection(object): a connection is passed instead of a channel, to functions that require a channel. """ + conn_opts = {} + transport_opts = self.transport_options + if transport_opts: + if 'max_retries' in transport_opts: + conn_opts['max_retries'] = transport_opts['max_retries'] + if 'interval_start' in transport_opts: + conn_opts['interval_start'] = transport_opts['interval_start'] + if 'interval_step' in transport_opts: + conn_opts['interval_step'] = transport_opts['interval_step'] + if 'interval_max' in transport_opts: + conn_opts['interval_max'] = transport_opts['interval_max'] + # make sure we're still connected, and if not refresh. - self.ensure_connection() + self.ensure_connection(**conn_opts) if self._default_channel is None: self._default_channel = self.channel() return self._default_channel diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py index 576181cf..edeba2ad 100644 --- a/t/unit/test_connection.py +++ b/t/unit/test_connection.py @@ -380,6 +380,32 @@ class test_Connection: defchan.close.assert_called_with() assert conn._default_channel is None + def test_default_channel_no_transport_options(self): + conn = self.conn + conn.ensure_connection = Mock() + + assert conn.default_channel + conn.ensure_connection.assert_called_with() + + def test_default_channel_transport_options(self): + conn = self.conn + conn.transport_options = options = { + 'max_retries': 1, + 'interval_start': 2, + 'interval_step': 3, + 'interval_max': 4, + 'ignore_this': True + } + conn.ensure_connection = Mock() + + assert conn.default_channel + conn.ensure_connection.assert_called_with(**{ + k: v for k, v in options.items() + if k in ['max_retries', + 'interval_start', + 'interval_step', + 'interval_max']}) + def test_ensure_connection(self): assert self.conn.ensure_connection()