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:
Gevorg Davoian
2016-10-25 00:22:12 +03:00
parent 2f425af5de
commit 1a2370ac91
2 changed files with 8 additions and 11 deletions

View File

@@ -43,11 +43,10 @@ automaton>=0.5.0 # Apache-2.0
# For common utilities # For common utilities
oslo.utils>=3.17.0 # Apache-2.0 oslo.utils>=3.17.0 # Apache-2.0
oslo.serialization>=1.10.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 # For lru caches and such
cachetools>=1.1.0 # MIT License cachetools>=1.1.0 # MIT License
# For deprecation of things # For deprecation of things
debtcollector>=1.2.0 # Apache-2.0 debtcollector>=1.2.0 # Apache-2.0

View File

@@ -24,12 +24,12 @@ import threading
import time import time
from oslo_utils import strutils from oslo_utils import strutils
import retrying
import six import six
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from sqlalchemy import pool as sa_pool from sqlalchemy import pool as sa_pool
from sqlalchemy import sql from sqlalchemy import sql
import tenacity
from taskflow import exceptions as exc from taskflow import exceptions as exc
from taskflow import logging from taskflow import logging
@@ -375,14 +375,12 @@ class Connection(base.Connection):
# Other failures we likely can't fix by retrying... # Other failures we likely can't fix by retrying...
return False return False
@retrying.retry(stop_max_attempt_number=max(0, int(max_retries)), @tenacity.retry(
# Ensure that the 2 ** retry number stop=tenacity.stop_after_attempt(max(0, int(max_retries))),
# is converted into milliseconds (thus why this wait=tenacity.wait_exponential(),
# multiplies by 1000.0) because thats what retrying reraise=True,
# lib. uses internally for whatever reason. retry=tenacity.retry_if_exception(_retry_on_exception)
wait_exponential_multiplier=1000.0, )
wrap_exception=False,
retry_on_exception=_retry_on_exception)
def _try_connect(engine): def _try_connect(engine):
# See if we can make a connection happen. # See if we can make a connection happen.
# #