def __init__( self, when=None, max_attempts=None, on_exception=None, stop=None, backoff=None, ): if stop is None: if max_attempts is not None: stop = stop_mod.after_attempt(max_attempts) else: stop = stop_mod.NEVER if on_exception is not None: when = when_mod.raises(on_exception) | when if when is None: when = self._DEFAULT_PREDICATE if backoff is None: backoff = backoff_mod.jittered() if not isinstance(backoff, backoff_mod.RetryBackoff): backoff = backoff_mod.from_iterable_factory(backoff) self._when = when self._backoff = backoff self._stop = stop
def test_jittered_backoff(): iterator = backoff.jittered()() first = next(iterator) assert 0 <= first <= 1 second = next(iterator) assert 0 <= second <= 2 third = next(iterator) assert 0 <= third <= 4 fourth = next(iterator) assert 0 <= fourth <= 8 fifth = next(iterator) assert 0 <= fifth <= 16
def __init__( self, when=None, max_attempts=None, on_exception=None, stop=None, backoff=None, ): if stop is not None: self._stop = stop elif max_attempts is not None: self._stop = stop_mod.after_attempt(max_attempts) else: self._stop = stop_mod.DISABLE self._predicate = when if on_exception is not None: self._predicate = when_mod.raises(on_exception) | self._predicate if self._predicate is None: self._predicate = self._DEFAULT_PREDICATE self._backoff = backoff_mod.jittered() if backoff is None else backoff