(&self)
| 116 | } |
| 117 | |
| 118 | async fn record_failure(&self) { |
| 119 | if !self.config.circuit_breaker_enabled { |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | let mut state = self.state.write().await; |
| 124 | match *state { |
| 125 | CircuitBreakerState::Closed { failure_count } => { |
| 126 | let new_count = failure_count + 1; |
| 127 | if new_count >= self.config.circuit_breaker_threshold { |
| 128 | *state = CircuitBreakerState::Open { |
| 129 | opened_at: Instant::now(), |
| 130 | }; |
| 131 | if self.config.debug { |
| 132 | warn!("Circuit breaker opened due to {} failures", new_count); |
| 133 | } |
| 134 | } else { |
| 135 | *state = CircuitBreakerState::Closed { |
| 136 | failure_count: new_count, |
| 137 | }; |
| 138 | } |
| 139 | } |
| 140 | CircuitBreakerState::HalfOpen => { |
| 141 | *state = CircuitBreakerState::Open { |
| 142 | opened_at: Instant::now(), |
| 143 | }; |
| 144 | if self.config.debug { |
| 145 | warn!("Circuit breaker reopened after failed recovery attempt"); |
| 146 | } |
| 147 | } |
| 148 | _ => {} |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /// Client statistics for monitoring |
no outgoing calls
no test coverage detected