Skip to main content

Module fallback

Module fallback 

Source
Expand description

Fallback chain adapter — tries services in priority order with per-service circuit breakers Fallback chain service adapter.

Implements crate::ports::ScrapingService by trying a prioritised list of inner services with per-service circuit breakers. When a service’s circuit is Open or its execution fails, the chain automatically moves to the next lower-priority service.

§Behaviour

  1. Services are tried in registration order (index 0 = highest priority).
  2. A service is skipped when its circuit breaker is crate::ports::CircuitState::Open and the reset timeout has not yet elapsed. The chain then probes it once the timeout passes (half-open probe).
  3. On success the corresponding circuit breaker records the success and the result is returned immediately — no further services are tried.
  4. On failure the circuit breaker records the failure and the next service is tried.
  5. If every service is exhausted the last error is propagated.

§Example

use std::sync::Arc;
use std::time::Duration;
use stygian_graph::adapters::fallback::FallbackChainService;
use stygian_graph::adapters::noop::NoopService;
use stygian_graph::adapters::resilience::CircuitBreakerImpl;

let chain = FallbackChainService::builder()
    .add(Arc::new(NoopService), CircuitBreakerImpl::new(3, Duration::from_secs(30)))
    .named("primary-with-plugin-fallback")
    .build();

Structs§

FallbackChainBuilder
Builder for FallbackChainService.
FallbackChainService
A ScrapingService that tries multiple inner services in priority order, automatically routing around open circuit breakers and failed services.

Functions§

default_fallback_breaker
Sensible default for a production circuit breaker on a fallback scraper.
default_primary_breaker
Sensible default for a production circuit breaker on a primary scraper.