use std::time::Duration;
#[derive(Debug, Clone)]
pub struct CircuitBreakerConfig {
pub failure_threshold: u32,
pub recovery_timeout: Duration,
pub success_threshold: f32,
pub half_open_max_calls: u32,
}
impl Default for CircuitBreakerConfig {
fn default() -> Self {
Self {
failure_threshold: 50,
recovery_timeout: Duration::from_secs(60),
success_threshold: 0.5,
half_open_max_calls: 3,
}
}
}
impl CircuitBreakerConfig {
#[must_use]
pub fn failure_threshold(mut self, threshold: u32) -> Self {
self.failure_threshold = threshold;
self
}
#[must_use]
pub fn recovery_timeout(mut self, timeout: Duration) -> Self {
self.recovery_timeout = timeout;
self
}
#[must_use]
pub fn success_threshold(mut self, threshold: f32) -> Self {
self.success_threshold = threshold.clamp(0.0, 1.0);
self
}
#[must_use]
pub fn half_open_max_calls(mut self, max_calls: u32) -> Self {
self.half_open_max_calls = max_calls;
self
}
}