diff options
author | Gevorg Davoian <gdavoian@mirantis.com> | 2016-10-25 00:22:12 +0300 |
---|---|---|
committer | Gevorg Davoian <gdavoian@mirantis.com> | 2016-11-03 13:36:16 +0000 |
commit | 1a2370ac917ed1f888ef98a45270912b08f27844 (patch) | |
tree | 64f16ef79d320ce327493e568f02f0b2d18e60c2 | |
parent | 2f425af5de6e53e63db6f2915e439879f3a5b54b (diff) | |
download | taskflow-1a2370ac917ed1f888ef98a45270912b08f27844.tar.gz |
Replace retrying with tenacity
This patch replaces the legacy retrying library with the newer
and more convenient tenacity one, taking into account that:
1) retrying uses milliseconds for wait times, but tenacity uses seconds;
2) retrying has a lot of numeric arguments for specifying behaviour
of decorated functions, while tenacity has a few of them, which are
specialized objects, thus making the retry-decorator more flexible.
Change-Id: I4b165d37b2ecc210f2b94c103b73eaab51529261
Closes-Bug: #1635404
-rw-r--r-- | requirements.txt | 3 | ||||
-rw-r--r-- | taskflow/persistence/backends/impl_sqlalchemy.py | 16 |
2 files changed, 8 insertions, 11 deletions
diff --git a/requirements.txt b/requirements.txt index f9b57f9..f7ce7e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -43,11 +43,10 @@ automaton>=0.5.0 # Apache-2.0 # For common utilities oslo.utils>=3.17.0 # Apache-2.0 oslo.serialization>=1.10.0 # Apache-2.0 -retrying!=1.3.0,>=1.2.3 # Apache-2.0 +tenacity>=3.2.1 # Apache-2.0 # For lru caches and such cachetools>=1.1.0 # MIT License # For deprecation of things debtcollector>=1.2.0 # Apache-2.0 - diff --git a/taskflow/persistence/backends/impl_sqlalchemy.py b/taskflow/persistence/backends/impl_sqlalchemy.py index 5dc2316..70dbc16 100644 --- a/taskflow/persistence/backends/impl_sqlalchemy.py +++ b/taskflow/persistence/backends/impl_sqlalchemy.py @@ -24,12 +24,12 @@ import threading import time from oslo_utils import strutils -import retrying import six import sqlalchemy as sa from sqlalchemy import exc as sa_exc from sqlalchemy import pool as sa_pool from sqlalchemy import sql +import tenacity from taskflow import exceptions as exc from taskflow import logging @@ -375,14 +375,12 @@ class Connection(base.Connection): # Other failures we likely can't fix by retrying... return False - @retrying.retry(stop_max_attempt_number=max(0, int(max_retries)), - # Ensure that the 2 ** retry number - # is converted into milliseconds (thus why this - # multiplies by 1000.0) because thats what retrying - # lib. uses internally for whatever reason. - wait_exponential_multiplier=1000.0, - wrap_exception=False, - retry_on_exception=_retry_on_exception) + @tenacity.retry( + stop=tenacity.stop_after_attempt(max(0, int(max_retries))), + wait=tenacity.wait_exponential(), + reraise=True, + retry=tenacity.retry_if_exception(_retry_on_exception) + ) def _try_connect(engine): # See if we can make a connection happen. # |