1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Enterprise Reliability Features
//!
//! This module provides production-ready reliability mechanisms:
//!
//! - **Circuit Breaker**: Automatic service degradation protection
//! - **Rate Limiting**: Token bucket rate limiting with multiple time windows
//! - **Failover**: Multi-endpoint failover strategies
//! - **Health Checks**: Automated endpoint health monitoring
//!
//! ## Circuit Breaker
//!
//! The circuit breaker prevents cascading failures by automatically
//! detecting failing services and rejecting requests until the service
//! recovers.
//!
//! ```no_run
//! # use api_huggingface::reliability::{CircuitBreaker, CircuitBreakerConfig};
//! # use std::time::Duration;
//! # async fn example() -> Result< (), Box< dyn std::error::Error > > {
//! let circuit_breaker = CircuitBreaker::new(
//! CircuitBreakerConfig {
//! failure_threshold : 5,
//! success_threshold : 2,
//! timeout : Duration::from_secs(60),
//! }
//! );
//!
//! let _result = circuit_breaker.execute(async {
//! Ok::< String, Box< dyn std::error::Error > >("response".to_string())
//! }).await;
//! # Ok(())
//! # }
//! ```
//!
//! ## Rate Limiting
//!
//! The rate limiter controls request rates using token bucket algorithm
//! with support for multiple time windows.
//!
//! ```no_run
//! # use api_huggingface::reliability::{RateLimiter, RateLimiterConfig};
//! # async fn example() -> Result< (), Box< dyn std::error::Error > > {
//! let rate_limiter = RateLimiter::new(
//! RateLimiterConfig {
//! requests_per_second : Some(10),
//! requests_per_minute : Some(500),
//! requests_per_hour : Some(10000),
//! }
//! );
//!
//! // Acquire permission before request
//! rate_limiter.acquire().await?;
//! // ... make your request ...
//! # Ok(())
//! # }
//! ```
//!
//! ## Failover
//!
//! The failover manager provides automatic failover to backup endpoints
//! with multiple strategies and health tracking.
//!
//! ```no_run
//! # use api_huggingface::reliability::{FailoverManager, FailoverConfig, FailoverStrategy};
//! # use std::time::Duration;
//! # async fn example() -> Result< (), Box< dyn std::error::Error > > {
//! let failover = FailoverManager::new(
//! FailoverConfig {
//! endpoints : vec![
//! "https://api-inference.huggingface.co".to_string(),
//! "https://backup.huggingface.co".to_string(),
//! ],
//! strategy : FailoverStrategy::Priority,
//! max_retries : 3,
//! failure_window : Duration::from_secs(300),
//! failure_threshold : 5,
//! }
//! ).map_err(|e| format!("{:?}", e))?;
//!
//! // Execute with automatic failover
//! let _result = failover.execute_with_failover(|_endpoint| {
//! Box::pin(async move {
//! Ok::< String, Box< dyn std::error::Error > >("response".to_string())
//! })
//! }).await;
//! # Ok(())
//! # }
//! ```
//!
//! ## Health Checks
//!
//! The health checker provides automated monitoring of endpoint health
//! with configurable strategies and background monitoring.
//!
//! ```no_run
//! # use api_huggingface::reliability::{HealthChecker, HealthCheckConfig, HealthCheckStrategy};
//! # use std::time::Duration;
//! # async fn example() -> Result< (), Box< dyn std::error::Error > > {
//! let health_checker = HealthChecker::new(
//! HealthCheckConfig {
//! endpoint : "https://api-inference.huggingface.co".to_string(),
//! strategy : HealthCheckStrategy::LightweightApi,
//! check_interval : Duration::from_secs(30),
//! timeout : Duration::from_secs(5),
//! unhealthy_threshold : 3,
//! }
//! );
//!
//! // Start background monitoring
//! let _monitor = health_checker.start_monitoring().await;
//!
//! // Check current health
//! let status = health_checker.get_status().await;
//! println!("Healthy : {}, Latency : {}ms", status.healthy, status.latency_ms);
//! # Ok(())
//! # }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;