plexus.cli.procedure.lua_dsl.primitives.retry module
Retry Primitive - Error handling with exponential backoff.
Provides: - Retry.with_backoff(fn, options) - Retry function with exponential backoff
- class plexus.cli.procedure.lua_dsl.primitives.retry.RetryPrimitive
Bases:
objectHandles retry logic with exponential backoff for procedures.
Enables workflows to: - Retry failed operations automatically - Use exponential backoff between attempts - Handle transient errors gracefully - Configure max attempts and delays
Initialize Retry primitive.
- __init__()
Initialize Retry primitive.
- with_backoff(fn: Callable, options: Dict[str, Any] | None = None) Any
Retry a function with exponential backoff.
- Args:
fn: Function to retry (Lua function) options: Dict with:
max_attempts: Maximum retry attempts (default: 3)
initial_delay: Initial delay in seconds (default: 1)
max_delay: Maximum delay in seconds (default: 60)
backoff_factor: Multiplier for delay (default: 2)
on_error: Optional callback when error occurs
- Returns:
Result from successful function call
- Raises:
Exception: If all retry attempts fail
- Example (Lua):
- local result = Retry.with_backoff(function()
– Try to fetch data from API local data = fetch_api_data() if not data then
error(“API returned no data”)
end return data
- end, {
max_attempts = 5, initial_delay = 2, backoff_factor = 2
})