retry
Automatically retry module execution on failure.
Syntax
result = Module(args) with retry: <count>
Type: Integer (non-negative)
Description
The retry option specifies the maximum number of retry attempts if a module call fails. The first execution is not counted as a retry, so retry: 3 means up to 4 total attempts (1 initial + 3 retries).
A common source of confusion: retry: 3 means 4 total attempts (1 initial + 3 retries). If you want exactly 3 attempts total, use retry: 2.
Without timeout, a hanging call blocks forever and never retries. Combine with timeout to ensure failed attempts actually fail and allow retries to proceed.
Examples
Basic Retry
response = HttpGet(url) with retry: 3
If the request fails, retry up to 3 more times before giving up.
Retry with Delay
result = FlakyService(input) with retry: 5, delay: 1s
Wait 1 second between retry attempts.
Retry with Exponential Backoff
response = ApiCall(request) with
retry: 5,
delay: 500ms,
backoff: exponential
Wait 500ms, 1s, 2s, 4s, 8s between successive retries.
Retry with Timeout
result = SlowOperation(data) with retry: 3, timeout: 10s
Each attempt has a 10-second timeout. Total possible time: 40s.
Retry with Fallback
value = GetConfig(key) with retry: 2, fallback: "default"
After all retries fail, return "default" instead of raising an error.
Behavior
- Execute the module
- If successful, return the result
- If failed and retries remaining:
- Apply delay (if specified)
- Retry the execution
- If failed and no retries remaining:
- Use fallback (if specified)
- Otherwise, raise
RetryExhaustedException
Error Details
When all retries are exhausted, a RetryExhaustedException is raised containing:
- Module name
- Total number of attempts
- History of all errors from each attempt
Example error message:
FlakyService failed after 4 attempts:
Attempt 1: Connection timeout
Attempt 2: Connection timeout
Attempt 3: Service unavailable
Attempt 4: Connection timeout
Related Options
- delay - Time between retries
- backoff - How delay increases
- timeout - Time limit per attempt
- fallback - Default value on failure
Diagnostics
| Warning/Error | Cause |
|---|---|
| High retry count | More than 10 retries specified |
| Negative value | Retry count must be >= 0 |
Best Practices
- Use moderate retry counts (2-5) for most operations
- Always pair with
timeoutto prevent hanging - Consider
delaywithbackoff: exponentialfor rate-limited APIs - Provide a
fallbackfor graceful degradation