gcp_sdk_gax::retry_policy

Trait RetryPolicyExt

Source
pub trait RetryPolicyExt: RetryPolicy + Sized {
    // Provided methods
    fn with_time_limit(
        self,
        maximum_duration: Duration,
    ) -> LimitedElapsedTime<Self> { ... }
    fn with_attempt_limit(
        self,
        maximum_attempts: u32,
    ) -> LimitedAttemptCount<Self> { ... }
}
Expand description

Extension trait for RetryPolicy

Provided Methods§

Source

fn with_time_limit(self, maximum_duration: Duration) -> LimitedElapsedTime<Self>

Decorate a RetryPolicy to limit the total elapsed time in the retry loop.

While the time spent in the retry loop (including time in backoff) is less than the prescribed duration the on_error() method returns the results of the inner policy. After that time it returns Exhausted if the inner policy returns Continue.

The remaining_time() function returns the remaining time. This is always Duration::ZERO once or after the policy’s expiration time is reached.

§Example
let d = std::time::Duration::from_secs(10);
let policy = Aip194Strict.with_time_limit(d);
assert!(policy.remaining_time(std::time::Instant::now(), 0) <= Some(d));
Source

fn with_attempt_limit(self, maximum_attempts: u32) -> LimitedAttemptCount<Self>

Decorate a RetryPolicy to limit the number of retry attempts.

This policy decorates an inner policy and limits the total number of attempts. Note that on_error() is not called before the initial (non-retry) attempt. Therefore, setting the maximum number of attempts to 0 or 1 results in no retry attempts.

The policy passes through the results from the inner policy as long as attempt_count < maximum_attempts. Once the maximum number of attempts is reached, the policy returns Exhausted if the inner policy returns Continue.

§Example
use std::time::Instant;
let policy = Aip194Strict.with_attempt_limit(3);
assert_eq!(policy.remaining_time(Instant::now(), 0), None);
assert!(policy.on_error(Instant::now(), 0, true, Error::authentication(format!("transient"))).is_continue());
assert!(policy.on_error(Instant::now(), 1, true, Error::authentication(format!("transient"))).is_continue());
assert!(policy.on_error(Instant::now(), 2, true, Error::authentication(format!("transient"))).is_continue());
assert!(policy.on_error(Instant::now(), 3, true, Error::authentication(format!("transient"))).is_exhausted());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§