Retry Policy
RetryPolicy
The RetryPolicy
class defines how retries should be handled for failed atoms within a workflow. It provides customizable options for retrying operations, such as setting the number of attempts, delay between retries, and handling specific exceptions.
Flexible Application:
- Can be applied at the workflow level (default for all atoms).
- Can be overridden by individual atoms with a custom retry policy.
Parameters
Optional Parameters (Defaults Provided):
max_attempts
(int): Maximum number of retry attempts.
Default:3
delay
(float): Initial delay in seconds between retry attempts.
Default:1.0
backoff_factor
(float): Multiplier to increase delay between each failed attempt.
Default:2.0
retry_exceptions
(tuple of exceptions): Specific exceptions on which retries are attempted. By default, retries are attempted on all exceptions (Exception
).
Default:(Exception,)
Default Behavior
If no custom retry policy is provided, the following defaults are used:
Usage Examples
1. Applying a Retry Policy to a Workflow
Define a retry policy for the entire workflow. This policy will be applied to all atoms unless overridden at the atom level.
2. Overriding a Retry Policy for a Specific Atom
Atoms can have their own retry policy, which overrides the workflow’s default policy.
3. Combining Workflow and Atom Policies
If both workflow-level and atom-level policies are specified, the atom’s policy takes precedence.
Key Features
-
Customizable Retry Logic:
- Adjust the number of attempts, delay, and backoff.
- Target specific exceptions for retries.
-
Exponential Backoff:
- Avoid excessive retry attempts by increasing delay incrementally with the
backoff_factor
.
- Avoid excessive retry attempts by increasing delay incrementally with the
-
Granular Control:
- Use workflow-level defaults for simplicity.
- Override defaults at the atom level for specific tasks.
Example Workflow with Retry Policy
Why Use RetryPolicy
?
- Reliability: Automatically handle transient failures with retries.
- Efficiency: Prevent infinite retry loops with customizable limits and backoff strategies.
- Control: Fine-tune retry behavior for specific workflows or tasks.
Enhance your workflow resilience with RetryPolicy
! 🔄
Was this page helpful?