Skip to main content

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).

Total attempts = retry + 1

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.

Always pair with timeout

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

  1. Execute the module
  2. If successful, return the result
  3. If failed and retries remaining:
    • Apply delay (if specified)
    • Retry the execution
  4. 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

Diagnostics

Warning/ErrorCause
High retry countMore than 10 retries specified
Negative valueRetry count must be >= 0

Best Practices

  • Use moderate retry counts (2-5) for most operations
  • Always pair with timeout to prevent hanging
  • Consider delay with backoff: exponential for rate-limited APIs
  • Provide a fallback for graceful degradation