Crate pravega_client_retry[][src]

Retry is a crate for retrying something that can fail with exponential backoff. It is designed to have a declarative interface for ease of use. It can be used as follows:

let retry_policy = RetryWithBackoff::default().max_tries(1);
let mut collection = vec![1, 2].into_iter();
let value = retry_sync(retry_policy, || match collection.next() {
    Some(n) if n == 2 => RetryResult::Success(n),
    Some(_) => RetryResult::Retry("not 2"),
    None => RetryResult::Fail("to the end"),
}).unwrap();

assert_eq!(value, 2);

The above will retry the code 1 times if it throws Err(Retry::Retry). If it throws a Err(Retry::Err) or returns successfully it will return immediately. The delay following each of the filed attempts would be 1, 10,respectively. If all retries fail, it will return Err(RetryErr) that has error message.

Modules

retry_async
retry_policy
retry_result
retry_sync

Macros

wrap_with_async_retry

wrap_with_async_retry! macro wraps any arbitrary async function with pravega_rust_client_retry::retry_async::retry_async This macro takes two parameters. The first parameter is the Retry policy which implements trait BackoffSchedule. The second parameter is the async function that needs to be wrapped within the retry logic. The function invocation will be retried only error returned by the function returns can_retry() as true.

wrap_with_sync_retry

wrap_with_sync_retry! macro wraps any arbitrary synchronous function with pravega_rust_client_retry::retry_sync::retry_sync This macro takes two parameters. The first parameter is the Retry policy which implements trait BackoffSchedule. The second parameter is the synchrounous function that needs to be wrapped within the retry logic. The function invocation will be retried only error returned by the function returns can_retry() as true.