Skip to main content

RetryingGateway

Struct RetryingGateway 

Source
pub struct RetryingGateway<G: ModelGateway> { /* private fields */ }
Expand description

A ModelGateway that retries an inner gateway under a RetryPolicy.

The wrapper is an ordinary gateway — no new trait, no runner option, off unless the host builds one — and every attempt sends the same ModelRequest.

  • Only ModelInvokeErrorKind::Transient and ModelInvokeErrorKind::TimedOut failures are retried. Permanent, Undecodable, InvalidRequest, Cancelled and UnknownOutcome are never retried, and there is no setting for that.
  • invoke and stream share the policy; each logical call counts its own attempts.
  • stream reads the inner stream’s first item before returning. An inner error, or a first item that is a StreamDelta::Error with a retryable kind, starts another attempt. Any other first item is handed on followed by the rest of the stream, and the call is never retried from then on — a failure after the first delta reaches the caller unchanged. An inner stream that ends before yielding any item is classified UnknownOutcome and never retried.
  • A wait is raced against the caller’s CallControl: cancellation during a wait returns Cancelled, and a wait that would reach the parent deadline returns the last error instead of waiting. The wrapper never extends the parent deadline and never cancels the parent token.
  • A server-requested delay (ModelInvokeError::retry_delay) is waited as given while it is at or below max_server_delay; above the ceiling the call fails at once. Without one, the wrapper uses its own jittered exponential backoff.
  • One tracing event per retry records the attempt, the failure kind and the wait.

Implementations§

Source§

impl<G: ModelGateway> RetryingGateway<G>

Source

pub fn new(inner: G, policy: RetryPolicy) -> Self

Wraps inner with policy. The wrapped value stays reachable through RetryingGateway::inner; a host that wants a shared trait object builds the wrapper around the concrete gateway and coerces Arc::new(RetryingGateway::new(gateway, policy)) to Arc<dyn ModelGateway>.

Source

pub fn policy(&self) -> &RetryPolicy

The retry policy in force.

Source

pub fn inner(&self) -> &G

The wrapped gateway.

Trait Implementations§

Source§

impl<G: Clone + ModelGateway> Clone for RetryingGateway<G>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<G: ModelGateway> Debug for RetryingGateway<G>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<G: ModelGateway> ModelGateway for RetryingGateway<G>

Source§

fn invoke<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 ModelRequest, control: &'life2 CallControl, ) -> Pin<Box<dyn Future<Output = Result<ModelOutput, ModelInvokeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Runs one logical invocation, returning the assembled ModelOutput, or a classified ModelInvokeError. Cancellation and the deadline arrive through control.
Source§

fn stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 ModelRequest, control: &'life2 CallControl, ) -> Pin<Box<dyn Future<Output = Result<ModelStream, ModelInvokeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Streams one logical output. Once any delta has been yielded, transparent retries are prohibited. The final Done alone supplies material for submission. Default implementation: degenerates to a single StreamDelta::Done after invoke — providers that never implemented streaming keep working through the same port; streaming providers override to expose real token increments.

Auto Trait Implementations§

§

impl<G> Forget for RetryingGateway<G>

§

impl<G> Freeze for RetryingGateway<G>
where G: Freeze,

§

impl<G> Move for RetryingGateway<G>

§

impl<G> RefUnwindSafe for RetryingGateway<G>
where G: RefUnwindSafe,

§

impl<G> Send for RetryingGateway<G>

§

impl<G> Sync for RetryingGateway<G>

§

impl<G> Unpin for RetryingGateway<G>
where G: Unpin,

§

impl<G> UnsafeUnpin for RetryingGateway<G>
where G: UnsafeUnpin,

§

impl<G> UnwindSafe for RetryingGateway<G>
where G: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more