diff options
author | Julien Danjou <julien@danjou.info> | 2016-05-17 09:55:26 +0200 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2016-05-17 17:23:12 +0200 |
commit | 663092d675bca7c2420665b820db9306e381d73f (patch) | |
tree | 6932acdd0c285c502f874ca48566670456835062 | |
parent | 3ac4f3f2d8ddfd60543b978026ce37ab2f767cab (diff) | |
download | oslo-db-663092d675bca7c2420665b820db9306e381d73f.tar.gz |
api: always enable retry_on_request
The current behavior makes by default retry_on_request does not work,
which is confusing. Nothing except the developer can raise a
RetryRequest, so there can not be any misunderstanding. Having to both
enable the switch *and* raise RetryRequest makes it more complicated
than it needs to be.
This patch simplifies the API by deprecating retry_on_request and
retry_on_request() decorator, enabling the exception everywhere
wrap_db_retry() is used.
Change-Id: I3c53b5c8ba99f460153256fb2e1e6ef01b67f41b
-rw-r--r-- | oslo_db/api.py | 10 | ||||
-rw-r--r-- | oslo_db/tests/test_api.py | 6 |
2 files changed, 8 insertions, 8 deletions
diff --git a/oslo_db/api.py b/oslo_db/api.py index 8cab3e5..6a58394 100644 --- a/oslo_db/api.py +++ b/oslo_db/api.py @@ -27,6 +27,7 @@ import logging import threading import time +from debtcollector import removals from oslo_utils import excutils from oslo_utils import importutils from oslo_utils import reflection @@ -106,6 +107,8 @@ class wrap_db_retry(object): :type exception_checker: callable """ + @removals.removed_kwarg("retry_on_request", + "Retry on request is always enabled") def __init__(self, retry_interval=0, max_retries=0, inc_retry_interval=False, max_retry_interval=0, retry_on_disconnect=False, @@ -113,15 +116,13 @@ class wrap_db_retry(object): exception_checker=lambda exc: False): super(wrap_db_retry, self).__init__() - self.db_error = () + self.db_error = (exception.RetryRequest, ) # default is that we re-raise anything unexpected self.exception_checker = exception_checker if retry_on_disconnect: self.db_error += (exception.DBConnectionError, ) if retry_on_deadlock: self.db_error += (exception.DBDeadlock, ) - if retry_on_request: - self.db_error += (exception.RetryRequest, ) self.retry_interval = retry_interval self.max_retries = max_retries self.inc_retry_interval = inc_retry_interval @@ -258,8 +259,7 @@ class DBAPI(object): inc_retry_interval=self.inc_retry_interval, max_retry_interval=self.max_retry_interval, retry_on_disconnect=retry_on_disconnect, - retry_on_deadlock=retry_on_deadlock, - retry_on_request=retry_on_request)(attr) + retry_on_deadlock=retry_on_deadlock)(attr) return attr diff --git a/oslo_db/tests/test_api.py b/oslo_db/tests/test_api.py index 6b13bae..ab33c8c 100644 --- a/oslo_db/tests/test_api.py +++ b/oslo_db/tests/test_api.py @@ -200,7 +200,7 @@ class DBReconnectTestCase(DBAPITestCase): class DBRetryRequestCase(DBAPITestCase): def test_retry_wrapper_succeeds(self): - @api.wrap_db_retry(max_retries=10, retry_on_request=True) + @api.wrap_db_retry(max_retries=10) def some_method(): pass @@ -209,7 +209,7 @@ class DBRetryRequestCase(DBAPITestCase): def test_retry_wrapper_reaches_limit(self): max_retries = 10 - @api.wrap_db_retry(max_retries=10, retry_on_request=True) + @api.wrap_db_retry(max_retries=10) def some_method(res): res['result'] += 1 raise exception.RetryRequest(ValueError()) @@ -223,7 +223,7 @@ class DBRetryRequestCase(DBAPITestCase): def exception_checker(exc): return isinstance(exc, ValueError) and exc.args[0] < 5 - @api.wrap_db_retry(max_retries=10, retry_on_request=True, + @api.wrap_db_retry(max_retries=10, exception_checker=exception_checker) def some_method(res): res['result'] += 1 |