diff options
-rw-r--r-- | oslo_db/api.py | 22 | ||||
-rw-r--r-- | oslo_db/tests/test_api.py | 4 |
2 files changed, 12 insertions, 14 deletions
diff --git a/oslo_db/api.py b/oslo_db/api.py index 93931f7..2f592e9 100644 --- a/oslo_db/api.py +++ b/oslo_db/api.py @@ -109,9 +109,9 @@ class wrap_db_retry(object): @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, + def __init__(self, retry_interval=1, max_retries=20, + inc_retry_interval=True, + max_retry_interval=10, retry_on_disconnect=False, retry_on_deadlock=False, retry_on_request=False, exception_checker=lambda exc: False): super(wrap_db_retry, self).__init__() @@ -221,10 +221,11 @@ class DBAPI(object): self._load_backend() self.use_db_reconnect = kwargs.get('use_db_reconnect', False) - self.retry_interval = kwargs.get('retry_interval', 1) - self.inc_retry_interval = kwargs.get('inc_retry_interval', True) - self.max_retry_interval = kwargs.get('max_retry_interval', 10) - self.max_retries = kwargs.get('max_retries', 20) + self._wrap_db_kwargs = {k: v for k, v in kwargs.items() + if k in ('retry_interval', + 'inc_retry_interval', + 'max_retry_interval', + 'max_retries')} def _load_backend(self): with self._lock: @@ -256,12 +257,9 @@ class DBAPI(object): if retry_on_disconnect or retry_on_deadlock or retry_on_request: attr = wrap_db_retry( - retry_interval=self.retry_interval, - max_retries=self.max_retries, - 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)(attr) + retry_on_deadlock=retry_on_deadlock, + **self._wrap_db_kwargs)(attr) return attr diff --git a/oslo_db/tests/test_api.py b/oslo_db/tests/test_api.py index ab33c8c..6863790 100644 --- a/oslo_db/tests/test_api.py +++ b/oslo_db/tests/test_api.py @@ -207,9 +207,9 @@ class DBRetryRequestCase(DBAPITestCase): some_method() def test_retry_wrapper_reaches_limit(self): - max_retries = 10 + max_retries = 2 - @api.wrap_db_retry(max_retries=10) + @api.wrap_db_retry(max_retries=max_retries) def some_method(res): res['result'] += 1 raise exception.RetryRequest(ValueError()) |