Python retrying.Retrying() Examples
The following are 9
code examples of retrying.Retrying().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
retrying
, or try the search function
.
Example #1
Source File: activity_retrying.py From botoflow with Apache License 2.0 | 6 votes |
def retry_on_exception(*args): """Takes a list of exceptions to retry on and retries, will automatically unpack ActivityTaskFailedError exceptions :param *args: exception classes to retry on :type *args: Iterable :rtype: function :return: callable function to be used with retry_on_exception in Retrying """ def _retry_exceptions(exception): if isinstance(exception, ActivityTaskFailedError): exception = exception.cause if isinstance(exception, args): return True return False return _retry_exceptions
Example #2
Source File: default_retries.py From exporters with BSD 3-Clause "New" or "Revised" License | 6 votes |
def initialized_retry(*dargs, **dkw): def wrap(f): @wraps(f) def wrapped_f(*args, **kw): if _retry_init: rargs, rkw = _retry_init(dargs, dkw) else: rargs, rkw = dargs, dkw return Retrying(*rargs, **rkw).call(_warn_about_exceptions(f), *args, **kw) return wrapped_f return wrap # for operations that shouldn't take longer than a few seconds (e.g. HTTP request) # will retry after 2s, 4s, 8s, 10s, 10s, 10s ... until the 10th attempt
Example #3
Source File: activity_retrying.py From botoflow with Apache License 2.0 | 5 votes |
def __init__(self, stop_max_attempt_number=None, stop_max_delay=None, wait_fixed=None, wait_random_min=None, wait_random_max=None, wait_incrementing_start=None, wait_incrementing_increment=None, wait_exponential_multiplier=None, wait_exponential_max=None, retry_on_exception=None, retry_on_result=None, wrap_exception=False, stop_func=None, wait_func=None): super(Retrying, self).__init__(stop=stop_func, wait=wait_func, stop_max_attempt_number=stop_max_attempt_number, stop_max_delay=stop_max_delay, wait_fixed=wait_fixed, wait_random_min=wait_random_min, wait_random_max=wait_random_max, wait_incrementing_start=wait_incrementing_start, wait_incrementing_increment=wait_incrementing_increment, wait_exponential_multiplier=wait_exponential_multiplier, wait_exponential_max=wait_exponential_max, retry_on_exception=retry_on_exception, retry_on_result=retry_on_result, wrap_exception=wrap_exception, stop_func=stop_func, wait_func=wait_func) # unfortunately retrying uses ms everywhere and we are using seconds (as in floats 0.5 is valid) # to remain consistent with botoflow, we fix all the times before passing the to retrying self._stop_max_attempt_number = 3 if stop_max_attempt_number is None else stop_max_attempt_number self._stop_max_delay = 1000 if stop_max_delay is None else int(stop_max_delay * 1000) self._wait_fixed = 1000 if wait_fixed is None else int(wait_fixed * 1000) self._wait_random_min = 0 if wait_random_min is None else int(wait_random_min * 1000) self._wait_random_max = 1000 if wait_random_max is None else int(wait_random_max * 1000) self._wait_incrementing_start = 0 if wait_incrementing_start is None else int(wait_incrementing_start * 1000) self._wait_incrementing_increment = (1000 if wait_incrementing_increment is None else int(wait_incrementing_increment * 1000)) self._wait_exponential_multiplier = (1 if wait_exponential_multiplier is None else int(wait_exponential_multiplier * 1000)) self._wait_exponential_max = (retrying.MAX_WAIT if wait_exponential_max is None else int(wait_exponential_max * 1000))
Example #4
Source File: default_retries.py From exporters with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _warn_about_exceptions(f, *args, **kw): try: return f(*args, **kw) except Exception as e: logging.warning("Retrying: {} (message was: {})".format( f.__name__, str(e))) raise
Example #5
Source File: default_retries.py From exporters with BSD 3-Clause "New" or "Revised" License | 5 votes |
def retry_generator(fn=None, max_retries=8, retry_multiplier=5.0, *args, **kwargs): @decorator def _decor_(fn, *args, **kwargs): """ Retry a generator. The if you don't expect already yielded items to be yielded again, the generator will need to keep state about what items have already been successfully yielded. """ for retry in range(1, max_retries + 1): try: generator = fn(*args, **kwargs) if not isinstance(generator, GeneratorType): msg = "@retry_generator cannot be used in non-generator functions" raise NonGeneratorError(msg) for i in generator: yield i except (StopIteration, NonGeneratorError): raise except Exception as e: if retry < max_retries: logging.warning("Retrying: {} (message was: {})".format( fn.__name__, str(e))) time.sleep(retry * retry_multiplier) else: raise else: break return _decor_(fn, *args, **kwargs) if fn is not None else _decor_
Example #6
Source File: base_product_case.py From presto-admin with Apache License 2.0 | 5 votes |
def retry(method_to_check, retry_timeout=RETRY_TIMEOUT, retry_interval=RETRY_INTERVAL): return Retrying(stop_max_delay=retry_timeout * 1000, wait_fixed=retry_interval * 1000).call(method_to_check)
Example #7
Source File: db_init.py From st2 with Apache License 2.0 | 5 votes |
def db_func_with_retry(db_func, *args, **kwargs): """ This method is a generic retry function to support database setup and cleanup. """ # Using as an annotation would be nice but annotations are evaluated at import # time and simple ways to use the annotation means the config gets read before # it is setup. Likely there is a way to use some proxies to delay the actual # reading of config values however this is lesser code. retrying_obj = retrying.Retrying( retry_on_exception=_retry_if_connection_error, wait_exponential_multiplier=cfg.CONF.database.connection_retry_backoff_mul * 1000, wait_exponential_max=cfg.CONF.database.connection_retry_backoff_max_s * 1000, stop_max_delay=cfg.CONF.database.connection_retry_max_delay_m * 60 * 1000 ) return retrying_obj.call(db_func, *args, **kwargs)
Example #8
Source File: bootstrap_utils.py From st2 with Apache License 2.0 | 5 votes |
def register_exchanges_with_retry(): def retry_if_io_error(exception): return isinstance(exception, socket.error) retrying_obj = retrying.Retrying( retry_on_exception=retry_if_io_error, wait_fixed=cfg.CONF.messaging.connection_retry_wait, stop_max_attempt_number=cfg.CONF.messaging.connection_retries ) return retrying_obj.call(register_exchanges)
Example #9
Source File: silverstripe.py From droopescan with GNU Affero General Public License v3.0 | 5 votes |
def _get(self, url, package): retry = Retrying(wait_exponential_multiplier=2000, wait_exponential_max=120000, retry_on_exception=_retry_msg) return retry.call(requests.get, url % package)