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> { ... }
fn continue_on_too_many_requests(self) -> TooManyRequests<Self> { ... }
fn continue_on_client_timeout(self) -> ClientTimeout<Self> { ... }
}Expand description
Extension trait for RetryPolicy
Provided Methods§
Sourcefn with_time_limit(self, maximum_duration: Duration) -> LimitedElapsedTime<Self>
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(&RetryState::new(true)) <= Some(d));Sourcefn with_attempt_limit(self, maximum_attempts: u32) -> LimitedAttemptCount<Self>
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
let policy = Aip194Strict.with_attempt_limit(3);
assert_eq!(policy.remaining_time(&RetryState::new(true)), None);
assert!(policy.on_error(&RetryState::new(true).set_attempt_count(0_u32), transient_error()).is_continue());
assert!(policy.on_error(&RetryState::new(true).set_attempt_count(1_u32), transient_error()).is_continue());
assert!(policy.on_error(&RetryState::new(true).set_attempt_count(2_u32), transient_error()).is_continue());
assert!(policy.on_error(&RetryState::new(true).set_attempt_count(3_u32), transient_error()).is_exhausted());
use google_cloud_gax::error::{Error, rpc::Code, rpc::Status};
fn transient_error() -> Error { Error::service(Status::default().set_code(Code::Unavailable)) }Sourcefn continue_on_too_many_requests(self) -> TooManyRequests<Self>
fn continue_on_too_many_requests(self) -> TooManyRequests<Self>
Decorate a RetryPolicy to continue on certain status codes.
This policy decorates an inner policy and retries any errors with HTTP status code “429 - TOO_MANY_REQUESTS” or where the service returns an error with code ResourceExhausted.
For other errors it returns the same value as the inner policy.
Note that ResourceExhausted is ambiguous and may cause problems with some services. The code is used for both “too many requests” and for “quota exceeded” problems. If the quota in question is some kind of rate limit, then using this policy may be helpful. If the quota is not a rate limit, then this retry policy may needlessly send the same RPC multiple times.
You should consult the documentation for the service and RPC in question before using this policy.
§Example
use google_cloud_gax::retry_policy::{Aip194Strict, RetryPolicy, RetryPolicyExt};
use google_cloud_gax::retry_state::RetryState;
let policy = Aip194Strict;
assert!(policy.on_error(&RetryState::new(true).set_attempt_count(0_u32), too_many_requests()).is_permanent());
let policy = Aip194Strict.continue_on_too_many_requests();
assert!(policy.on_error(&RetryState::new(true).set_attempt_count(0_u32), too_many_requests()).is_continue());
use google_cloud_gax::error::{Error, rpc::Code, rpc::Status};
fn too_many_requests() -> Error { Error::service(Status::default().set_code(Code::ResourceExhausted)) }Sourcefn continue_on_client_timeout(self) -> ClientTimeout<Self>
fn continue_on_client_timeout(self) -> ClientTimeout<Self>
Decorate a RetryPolicy to continue on client-side timeouts.
This policy decorates an inner policy and retries any client-side timeout errors for idempotent requests. For other errors it returns the same value as the inner policy.
This policy is useful if you want to ignore connection timeouts, or retry if the service is taking too long to respond. Be aware that a client-side timeout may occur even after the service receives the request. If your request has side-effects, such as creating or deleting resources, it may be unsafe to retry the operation.
§Example
use google_cloud_gax::retry_policy::{Aip194Strict, RetryPolicy, RetryPolicyExt};
use google_cloud_gax::retry_state::RetryState;
let policy = Aip194Strict;
assert!(policy.on_error(&RetryState::new(false).set_attempt_count(0_u32), timeout()).is_permanent());
let policy = Aip194Strict.continue_on_client_timeout();
assert!(policy.on_error(&RetryState::new(true).set_attempt_count(0_u32), timeout()).is_continue());
fn timeout() -> Error {
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".