Skip to main content

RetryStrategy

Trait RetryStrategy 

Source
pub trait RetryStrategy:
    Debug
    + Send
    + Sync {
    // Required method
    fn retry_after(
        &self,
        request: &RetryRequest,
        reason: &RetryReason,
    ) -> Option<RetryAction>;
}
Expand description

A strategy that decides whether and when to retry a failed operation.

Implement this trait to provide custom retry behavior. The SDK calls retry_after each time a retryable failure occurs, passing the request metadata and the reason for the failure.

Return Some(RetryAction) to retry after the specified duration, or None to stop retrying and propagate the error.

§Example

use couchbase_core::retry::{RetryStrategy, RetryAction, RetryRequest, RetryReason};
use std::fmt::Debug;
use std::time::Duration;

#[derive(Debug)]
struct FixedDelayRetry(Duration);

impl RetryStrategy for FixedDelayRetry {
    fn retry_after(&self, request: &RetryRequest, reason: &RetryReason) -> Option<RetryAction> {
        if request.retry_attempts < 3 {
            Some(RetryAction::new(self.0))
        } else {
            None // give up after 3 attempts
        }
    }
}

Required Methods§

Source

fn retry_after( &self, request: &RetryRequest, reason: &RetryReason, ) -> Option<RetryAction>

Decides whether to retry an operation and how long to wait.

  • request — Metadata about the in-flight request (attempt count, idempotency, etc.).
  • reason — Why the operation failed.

Return Some(RetryAction) to retry, or None to stop.

Implementors§