agora.retry package¶
Submodules¶
agora.retry.backoff module¶
-
class
agora.retry.backoff.Backoff[source]¶ Bases:
objectProvides the amount of time to wait before trying again.
-
class
agora.retry.backoff.BinaryExponentialBackoff(base_delay)[source]¶ Bases:
agora.retry.backoff.ExponentialBackoffAn ExponentialBackoffStrategy with a base of 2.
For example, with a base_delay of 2, this strategy will yield backoffs of 2, 4, 6, 16, etc.
- Param:
base_delay: The base delay, in seconds.
-
class
agora.retry.backoff.ConstantBackoff(duration)[source]¶ Bases:
agora.retry.backoff.BackoffA backoff strategy that always returns the provided duration
- Parameters:
duration (
float) – The duration, in seconds.
-
class
agora.retry.backoff.ExponentialBackoff(base_delay, base)[source]¶ Bases:
agora.retry.backoff.BackoffA backoff strategy that exponentially increases based off of the number of attempts.
For example, with a base_delay of 2 and a base of 3, this strategy will yield backoffs of 2, 6, 16, 54, etc.
- Parameters:
base_delay (
float) – The base delay, in seconds.base (
float) – The base by which to exponentially increase delay by.
-
class
agora.retry.backoff.LinearBackoff(base_delay)[source]¶ Bases:
agora.retry.backoff.BackoffA backoff strategy that linearly increases based off of the number of attempts.
For example, with a base_delay of 2, this strategy will yield backoffs of 2, 4, 6, 8, etc.
- Parameters:
base_delay (
float) – The base delay, in seconds.
agora.retry.strategy module¶
-
class
agora.retry.strategy.BackoffStrategy(backoff, max_backoff)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that will delay the next retry, provided the action raised an error.
- Param:
backoff: The :class:`Backoff <agora.retry.backoff.Backoff> to use to determine the amount of time to delay.
- Parameters:
max_backoff (
float) – The maximum backoff, in seconds.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.strategy.BackoffWithJitterStrategy(backoff, max_backoff, jitter)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that will delay the next retry, with jitter induced on the delay provided by backoff.
The jitter parameter is a percentage of the total delay (after capping) that the timing can be off by. For example, a capped delay of 0.1s with a jitter of 0.1 will result in a delay of 0.1s +/- 0.01s.
- Param:
backoff: The :class:`Backoff <agora.retry.backoff.Backoff> to use to determine the amount of time to delay.
- Parameters:
max_backoff (
float) – The maximum backoff, in seconds.jitter (
float) – A percentage of the total delay that timing can be off by.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.strategy.LimitStrategy(max_attempts)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that limits the total umber of retries.
- Parameters:
max_attempts – The max number of attempts. Should be greater than 1, since the action is evaluated first.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.strategy.NonRetriableErrorsStrategy(non_retriable_errors)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that specifies which errors should not be retried.
- Param:
non_retriable_errors: A list of
Exceptionclasses that shouldn’t be retried.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.strategy.RetriableErrorsStrategy(retriable_errors)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that specifies which errors can be retried.
- Param:
retriable_errors: A list of
Exceptionclasses that can be retried.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.strategy.Strategy[source]¶ Bases:
objectDetermines whether or not an action should be retried. Strategies are allowed to delay or cause other side effects.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
Module contents¶
-
class
agora.retry.Backoff[source]¶ Bases:
objectProvides the amount of time to wait before trying again.
-
class
agora.retry.BackoffStrategy(backoff, max_backoff)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that will delay the next retry, provided the action raised an error.
- Param:
backoff: The :class:`Backoff <agora.retry.backoff.Backoff> to use to determine the amount of time to delay.
- Parameters:
max_backoff (
float) – The maximum backoff, in seconds.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.BackoffWithJitterStrategy(backoff, max_backoff, jitter)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that will delay the next retry, with jitter induced on the delay provided by backoff.
The jitter parameter is a percentage of the total delay (after capping) that the timing can be off by. For example, a capped delay of 0.1s with a jitter of 0.1 will result in a delay of 0.1s +/- 0.01s.
- Param:
backoff: The :class:`Backoff <agora.retry.backoff.Backoff> to use to determine the amount of time to delay.
- Parameters:
max_backoff (
float) – The maximum backoff, in seconds.jitter (
float) – A percentage of the total delay that timing can be off by.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.BinaryExponentialBackoff(base_delay)[source]¶ Bases:
agora.retry.backoff.ExponentialBackoffAn ExponentialBackoffStrategy with a base of 2.
For example, with a base_delay of 2, this strategy will yield backoffs of 2, 4, 6, 16, etc.
- Param:
base_delay: The base delay, in seconds.
-
class
agora.retry.ConstantBackoff(duration)[source]¶ Bases:
agora.retry.backoff.BackoffA backoff strategy that always returns the provided duration
- Parameters:
duration (
float) – The duration, in seconds.
-
class
agora.retry.ExponentialBackoff(base_delay, base)[source]¶ Bases:
agora.retry.backoff.BackoffA backoff strategy that exponentially increases based off of the number of attempts.
For example, with a base_delay of 2 and a base of 3, this strategy will yield backoffs of 2, 6, 16, 54, etc.
- Parameters:
base_delay (
float) – The base delay, in seconds.base (
float) – The base by which to exponentially increase delay by.
-
class
agora.retry.LimitStrategy(max_attempts)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that limits the total umber of retries.
- Parameters:
max_attempts – The max number of attempts. Should be greater than 1, since the action is evaluated first.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.LinearBackoff(base_delay)[source]¶ Bases:
agora.retry.backoff.BackoffA backoff strategy that linearly increases based off of the number of attempts.
For example, with a base_delay of 2, this strategy will yield backoffs of 2, 4, 6, 8, etc.
- Parameters:
base_delay (
float) – The base delay, in seconds.
-
class
agora.retry.NonRetriableErrorsStrategy(non_retriable_errors)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that specifies which errors should not be retried.
- Param:
non_retriable_errors: A list of
Exceptionclasses that shouldn’t be retried.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.RetriableErrorsStrategy(retriable_errors)[source]¶ Bases:
agora.retry.strategy.StrategyA strategy that specifies which errors can be retried.
- Param:
retriable_errors: A list of
Exceptionclasses that can be retried.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
class
agora.retry.Strategy[source]¶ Bases:
objectDetermines whether or not an action should be retried. Strategies are allowed to delay or cause other side effects.
-
should_retry(attempts, e)[source]¶ Returns whether or not to retry, based on this strategy.
- Parameters:
attempts (
int) – Tee number of attempts that have occurred. Starts at 1, since the action is evaluated first.e (
Exception) – TheExceptionthat was raised.
- Return type:
bool- Returns:
A bool indicating whether the action should be retried, based on this strategy.
-
-
agora.retry.retry(strategies, f, *args, **kwargs)[source]¶ Executes the provided function, potentially multiple times based off the provided strategies. Retry will block until the action is successful, or one of the provided strategies indicate no further retries should be performed.
The strategies are executed in the provided order, so any strategies that induce delays should be specified last.
- Parameters:
strategies (
List[Strategy]) – The list of<agora.retry.strategy.Strategy>objects to usef (
Callable) – A Callable to execute with the provided args and kwargs.
- Returns:
The return value of f.