summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-11-02 00:35:24 -0500
committerDan McGee <dan@archlinux.org>2011-11-02 12:58:37 -0500
commitf3be023b3c0ce53cbb473754e51fd2a092507194 (patch)
tree35da5756df5bfbf548611479d22cd26b1299f8f0
parent9cd10feedd89a626be126f7b4978f10cb59ad7fa (diff)
downloadkombu-f3be023b3c0ce53cbb473754e51fd2a092507194.tar.gz
Accept max_retries=0 as a valid value
This should be interpreted as distinct from 'None', which still means 'retry forever'. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--kombu/connection.py18
-rw-r--r--kombu/tests/test_utils.py7
-rw-r--r--kombu/utils/__init__.py2
3 files changed, 17 insertions, 10 deletions
diff --git a/kombu/connection.py b/kombu/connection.py
index 683e0a9c..1d9bff2d 100644
--- a/kombu/connection.py
+++ b/kombu/connection.py
@@ -267,10 +267,8 @@ class BrokerConnection(object):
"""
- max_retries = max_retries or 0
-
@wraps(fun)
- def _insured(*args, **kwargs):
+ def _ensured(*args, **kwargs):
got_connection = 0
for retries in count(0):
try:
@@ -278,14 +276,16 @@ class BrokerConnection(object):
except self.connection_errors + self.channel_errors, exc:
self._debug("ensure got exception: %r" % (exc, ),
exc_info=sys.exc_info())
- if got_connection or \
- max_retries and retries > max_retries:
+ if got_connection:
+ raise
+ if max_retries is not None and retries > max_retries:
raise
errback and errback(exc, 0)
self._connection = None
self.close()
- remaining_retries = max_retries and \
- max(max_retries - retries, 1)
+ remaining_retries = None
+ if max_retries is not None:
+ remaining_retries = max(max_retries - retries, 1)
self.ensure_connection(errback,
remaining_retries,
interval_start,
@@ -298,8 +298,8 @@ class BrokerConnection(object):
on_revive(new_channel)
got_connection += 1
- _insured.func_name = _insured.__name__ = "%s(insured)" % fun.__name__
- return _insured
+ _ensured.func_name = _ensured.__name__ = "%s(ensured)" % fun.__name__
+ return _ensured
def autoretry(self, fun, channel=None, **ensure_options):
"""Decorator for functions supporting a ``channel`` keyword argument.
diff --git a/kombu/tests/test_utils.py b/kombu/tests/test_utils.py
index 33a7df31..7c170ddc 100644
--- a/kombu/tests/test_utils.py
+++ b/kombu/tests/test_utils.py
@@ -209,3 +209,10 @@ class test_retry_over_time(unittest.TestCase):
self.myfun, self.Predicate,
max_retries=1, errback=self.errback, interval_max=14)
self.assertEqual(self.index, 2)
+
+ @insomnia
+ def test_retry_never(self):
+ self.assertRaises(self.Predicate, utils.retry_over_time,
+ self.myfun, self.Predicate,
+ max_retries=0, errback=self.errback, interval_max=14)
+ self.assertEqual(self.index, 1)
diff --git a/kombu/utils/__init__.py b/kombu/utils/__init__.py
index 939bc5ec..736603be 100644
--- a/kombu/utils/__init__.py
+++ b/kombu/utils/__init__.py
@@ -142,7 +142,7 @@ def retry_over_time(fun, catch, args=[], kwargs={}, errback=None,
try:
return fun(*args, **kwargs)
except catch, exc:
- if max_retries and retries > max_retries:
+ if max_retries is not None and retries > max_retries:
raise
if errback:
errback(exc, interval)