Skip to main content

Module retry_policy

Module retry_policy 

Source
Expand description

Defines traits for retry policies and some common implementations.

The client libraries automatically retry RPCs when (1) they fail due to transient errors and the RPC is idempotent, (2) or failed before an RPC was started. That is, when it is safe to attempt the RPC more than once.

Applications may override the default behavior, increasing the retry attempts, or changing what errors are considered safe to retry.

This module defines the traits for retry policies and some common implementations.

To configure the default throttler for a client, use ClientBuilder::with_retry_policy. To configure the retry policy used for a specific request, use RequestOptionsBuilder::with_retry_policy.

§Examples

Create a policy that only retries transient errors, and retries for at most 10 seconds or at most 5 attempts: whichever limit is reached first stops the retry loop.

use std::time::Duration;
let policy = Aip194Strict.with_time_limit(Duration::from_secs(10)).with_attempt_limit(5);

Create a policy that retries on any error (even when unsafe to do so), and stops retrying after 5 attempts or 10 seconds, whichever limit is reached first stops the retry loop.

use std::time::Duration;
let policy = AlwaysRetry.with_time_limit(Duration::from_secs(10)).with_attempt_limit(5);

Structs§

Aip194Strict
A retry policy that strictly follows AIP-194.
AlwaysRetry
A retry policy that retries all errors.
ClientTimeout
A retry policy decorator that continues on client timeouts.
LimitedAttemptCount
A retry policy decorator that limits the number of attempts.
LimitedElapsedTime
A retry policy decorator that limits the total time in the retry loop.
LimitedElapsedTimeError
Error indicating that the maximum elapsed time for retries has been exceeded.
NeverRetry
A retry policy that never retries.
RetryPolicyArg
A helper type to use RetryPolicy in client and request options.
TooManyRequests
A retry policy decorator that continues on ResourceExhausted or TOO_MANY_REQUESTS.

Traits§

RetryPolicy
Determines how errors are handled in the retry loop.
RetryPolicyExt
Extension trait for RetryPolicy