pub struct RetryLayer { /* private fields */ }retry only.Expand description
Retries with a RetryPolicy, and optionally reads the body of a 429 to tell a permanent error from a rate
limit first.
RetryLayer::new(policy) retries exactly like tower::retry::RetryLayer::new(policy). With
RetryLayer::permanent_429, the body of each 429 is read (up to RetryLayer::body_limit) and given to a
function; when it returns true, the response is marked Permanent and returned at once. The body is put back,
so the caller (and a generated client’s error) still sees all of it.
use timvw_rust_runtime::retry::{openai_insufficient_quota, RetryLayer, RetryPolicy};
use timvw_rust_runtime::{Client, ReqwestService};
let client = Client::from_service(ReqwestService::default())
.layer(RetryLayer::new(RetryPolicy::default()).permanent_429(openai_insufficient_quota));Implementations§
Source§impl RetryLayer
impl RetryLayer
Sourcepub fn new(policy: RetryPolicy) -> Self
pub fn new(policy: RetryPolicy) -> Self
Retries with policy, without reading any body.
Sourcepub fn permanent_429<F>(self, is_permanent: F) -> Self
pub fn permanent_429<F>(self, is_permanent: F) -> Self
Reads the body of each 429 and does not retry it when is_permanent returns true for the body’s bytes.
A body longer than RetryLayer::body_limit, or one that fails to read, is not given to is_permanent: the
response is retried as a rate limit, and the caller still reads the whole body (or its error).
Sourcepub fn body_limit(self, limit: usize) -> Self
pub fn body_limit(self, limit: usize) -> Self
How many bytes of a 429 body are read to classify it (default DEFAULT_BODY_LIMIT, 64 KiB).
Sourcepub fn policy(&self) -> &RetryPolicy
pub fn policy(&self) -> &RetryPolicy
The retry policy.
Trait Implementations§
Source§impl Clone for RetryLayer
impl Clone for RetryLayer
Source§impl Debug for RetryLayer
impl Debug for RetryLayer
Source§impl Default for RetryLayer
Retries with RetryPolicy::default.
impl Default for RetryLayer
Retries with RetryPolicy::default.