PollingErrorPolicyExt

Trait PollingErrorPolicyExt 

Source
pub trait PollingErrorPolicyExt: PollingErrorPolicy + 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 PollingErrorPolicy

Provided Methods§

Source

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

Decorate a PollingErrorPolicy to limit the total elapsed time in the polling loop.

While the time spent in the polling 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.

§Example
use polling_error_policy::*;
use std::time::Duration;
let policy = Aip194Strict.with_time_limit(Duration::from_secs(10)).with_attempt_limit(3);
let state = PollingState::default().set_attempt_count(4_u32);
assert!(policy.on_error(&state, 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)) }
Source

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

Decorate a PollingErrorPolicy to limit the number of poll attempts.

This policy decorates an inner policy and limits the total number of attempts. Note that on_error() is called only after a polling attempt. Therefore, setting the maximum number of attempts to 0 or 1 results in no polling after the LRO starts.

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, and passes the inner policy result otherwise.

§Example
use polling_error_policy::*;
let policy = Aip194Strict.with_attempt_limit(3);
assert!(policy.on_error(&PollingState::default().set_attempt_count(0_u32), transient_error()).is_continue());
assert!(policy.on_error(&PollingState::default().set_attempt_count(1_u32), transient_error()).is_continue());
assert!(policy.on_error(&PollingState::default().set_attempt_count(2_u32), transient_error()).is_continue());
assert!(policy.on_error(&PollingState::default().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)) }

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§