Merge "Use unified decorator for retries"
This commit is contained in:
@@ -17,7 +17,7 @@ import uuid
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_service import loopingcall
|
||||
import retrying
|
||||
import six
|
||||
from webob import response
|
||||
|
||||
@@ -217,10 +217,11 @@ class Controller(object):
|
||||
for action_id in list(actions):
|
||||
if 'getCredentials' in action_id:
|
||||
|
||||
@loopingcall.RetryDecorator(max_retry_count=10,
|
||||
inc_sleep_time=2,
|
||||
max_sleep_time=60,
|
||||
exceptions=(TypeError))
|
||||
@retrying.retry(retry_on_exception=lambda e: isinstance(e,
|
||||
TypeError),
|
||||
wait_random_min=1000,
|
||||
wait_random_max=10000,
|
||||
stop_max_delay=30000)
|
||||
def _get_creds(client, task_id, environment_id):
|
||||
result = m_cli.actions.get_result(environment_id,
|
||||
task_id)['result']
|
||||
|
@@ -15,12 +15,11 @@
|
||||
import collections
|
||||
import functools as func
|
||||
|
||||
import eventlet
|
||||
import jsonschema
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from murano.common.i18n import _, _LE
|
||||
from murano.common.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -210,50 +209,6 @@ def build_entity_map(value):
|
||||
return id_map
|
||||
|
||||
|
||||
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2):
|
||||
"""Retry calling the decorated function using an exponential backoff.
|
||||
|
||||
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
|
||||
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
|
||||
|
||||
:param ExceptionToCheck: the exception to check. may be a tuple of
|
||||
exceptions to check
|
||||
:type ExceptionToCheck: Exception or tuple
|
||||
:param tries: number of times to try (not retry) before giving up
|
||||
:type tries: int
|
||||
:param delay: initial delay between retries in seconds
|
||||
:type delay: int
|
||||
:param backoff: backoff multiplier e.g. value of 2 will double the delay
|
||||
each retry
|
||||
:type backoff: int
|
||||
"""
|
||||
|
||||
def deco_retry(f):
|
||||
@func.wraps(f)
|
||||
def f_retry(*args, **kwargs):
|
||||
mtries, mdelay = tries, delay
|
||||
forever = mtries == -1
|
||||
while forever or mtries > 1:
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
except ExceptionToCheck as e:
|
||||
LOG.exception(_LE("An exception occurred {exc}. Retrying "
|
||||
"in {time} seconds").format(exc=e,
|
||||
time=mdelay))
|
||||
eventlet.sleep(mdelay)
|
||||
|
||||
if not forever:
|
||||
mtries -= 1
|
||||
|
||||
if mdelay < 60:
|
||||
mdelay *= backoff
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return f_retry
|
||||
|
||||
return deco_retry
|
||||
|
||||
|
||||
def handle(f):
|
||||
"""Handles exception in wrapped function and writes to LOG."""
|
||||
|
||||
|
Reference in New Issue
Block a user