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
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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.
|
||||
#
|
||||
|
Reference in New Issue
Block a user