Merge "Use unified decorator for retries"
This commit is contained in:
@@ -17,7 +17,7 @@ import uuid
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_service import loopingcall
|
import retrying
|
||||||
import six
|
import six
|
||||||
from webob import response
|
from webob import response
|
||||||
|
|
||||||
@@ -217,10 +217,11 @@ class Controller(object):
|
|||||||
for action_id in list(actions):
|
for action_id in list(actions):
|
||||||
if 'getCredentials' in action_id:
|
if 'getCredentials' in action_id:
|
||||||
|
|
||||||
@loopingcall.RetryDecorator(max_retry_count=10,
|
@retrying.retry(retry_on_exception=lambda e: isinstance(e,
|
||||||
inc_sleep_time=2,
|
TypeError),
|
||||||
max_sleep_time=60,
|
wait_random_min=1000,
|
||||||
exceptions=(TypeError))
|
wait_random_max=10000,
|
||||||
|
stop_max_delay=30000)
|
||||||
def _get_creds(client, task_id, environment_id):
|
def _get_creds(client, task_id, environment_id):
|
||||||
result = m_cli.actions.get_result(environment_id,
|
result = m_cli.actions.get_result(environment_id,
|
||||||
task_id)['result']
|
task_id)['result']
|
||||||
|
@@ -15,12 +15,11 @@
|
|||||||
import collections
|
import collections
|
||||||
import functools as func
|
import functools as func
|
||||||
|
|
||||||
import eventlet
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from murano.common.i18n import _, _LE
|
from murano.common.i18n import _
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@@ -210,50 +209,6 @@ def build_entity_map(value):
|
|||||||
return id_map
|
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):
|
def handle(f):
|
||||||
"""Handles exception in wrapped function and writes to LOG."""
|
"""Handles exception in wrapped function and writes to LOG."""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user