pub struct CascadeFailover { /* private fields */ }Expand description
Priority-ordered cascade failover across named worker tiers.
Tries tiers from highest priority (index 0) to lowest. Within each tier
the configured number of retries is attempted before advancing to the next.
Each attempt is individually time-bounded by the tier’s timeout.
§Typical tier ordering
1. Premium (e.g. Anthropic) — lowest latency, highest cost, short timeout
2. Standard (e.g. OpenAI) — medium cost, medium timeout
3. Local fallback (LlamaCpp) — zero cost, longer timeout§Example
use std::time::Duration;
use tokio_prompt_orchestrator::config::WorkerKind;
use tokio_prompt_orchestrator::routing::cascade::{CascadeFailover, FailoverTier};
let failover = CascadeFailover::new(vec![
FailoverTier::new("premium", WorkerKind::Anthropic, Duration::from_secs(10), 0),
FailoverTier::new("standard", WorkerKind::OpenAi, Duration::from_secs(20), 1),
FailoverTier::new("local", WorkerKind::LlamaCpp, Duration::from_secs(60), 2),
]);
let result = failover.call(|kind| async move {
// Your inference call here
Ok::<String, String>(format!("response from {:?}", kind))
}).await;
match result {
Ok(r) => println!("Succeeded on tier '{}': {}", r.tier_name, r.value),
Err(e) => eprintln!("All tiers failed: {e}"),
}Implementations§
Source§impl CascadeFailover
impl CascadeFailover
Sourcepub fn new(tiers: Vec<FailoverTier>) -> Self
pub fn new(tiers: Vec<FailoverTier>) -> Self
Sourcepub fn with_tier(self, tier: FailoverTier) -> Self
pub fn with_tier(self, tier: FailoverTier) -> Self
Sourcepub fn tier_count(&self) -> usize
pub fn tier_count(&self) -> usize
Sourcepub async fn call<F, Fut, T>(
&self,
f: F,
) -> Result<FailoverResult<T>, FailoverExhausted>
pub async fn call<F, Fut, T>( &self, f: F, ) -> Result<FailoverResult<T>, FailoverExhausted>
Execute f against tiers in priority order, respecting per-tier
timeouts and retries.
f receives the WorkerKind of the current tier and must return a
future that resolves to Ok(T) on success or Err(String) on failure.
§Errors
Returns FailoverExhausted if every attempt on every tier fails.
§Panics
This function does not panic.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CascadeFailover
impl RefUnwindSafe for CascadeFailover
impl Send for CascadeFailover
impl Sync for CascadeFailover
impl Unpin for CascadeFailover
impl UnsafeUnpin for CascadeFailover
impl UnwindSafe for CascadeFailover
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request