pub async fn retry_with_policy<F, Fut, T>(
policy: &RetryPolicy,
operation_name: &str,
context: &str,
operation: F,
) -> Result<T>Expand description
What: Retry an operation with exponential backoff and jitter.
Inputs:
policy: Retry policy configurationoperation_name: Name of the operation for loggingcontext: Operation context (query/package name) for error messagesoperation: Async closure that performs the operation and returnsResult<T>
Output:
Result<T>from the operation, or the last error after all retries exhausted
Details:
- Implements exponential backoff:
delay = min(initial_delay * 2^attempt, max_delay) - Adds random jitter:
final_delay = delay + random(0..=jitter_max) - Respects Retry-After header when available from response errors
- Logs retry attempts with tracing
- Returns immediately on success or non-retryable errors
- Preserves operation context in error messages
ยงErrors
- Returns context-specific errors (
SearchFailed,InfoFailed, etc.) with preserved context - Returns
Err(ArchToolkitError::Parse)for non-retryable errors