Retry policy
RetryPolicy #
Bases: Protocol
Policy interface to control step retries after failures.
Implementations decide whether to retry and how long to wait before the next attempt based on elapsed time, number of attempts, and the last error.
See Also
Source code in workflows/retry_policy.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
next #
next(elapsed_time: float, attempts: int, error: Exception) -> float | None
Decide if another retry should occur and the delay before it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elapsed_time
|
float
|
Seconds since the first failure. |
required |
attempts
|
int
|
Number of attempts made so far. |
required |
error
|
Exception
|
The last exception encountered. |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
float | None: Seconds to wait before retrying, or |
Source code in workflows/retry_policy.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
ConstantDelayRetryPolicy #
Retry at a fixed interval up to a maximum number of attempts.
Examples:
@step(retry_policy=ConstantDelayRetryPolicy(delay=5, maximum_attempts=10))
async def flaky(self, ev: StartEvent) -> StopEvent:
...
Source code in workflows/retry_policy.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
next #
next(elapsed_time: float, attempts: int, error: Exception) -> float | None
Return the fixed delay while attempts remain; otherwise None.
Source code in workflows/retry_policy.py
60 61 62 63 64 65 66 67 | |