refactor: Update charging-engine dependencies and fix rate limiter configuration

- Upgrade tower_governor from 0.4.2 to 0.8.0 and add governor 0.10.4 dependency
- Add thiserror 2.0.18 for error handling
- Update dev dependencies: tokio-test to 0.4.5, mockall to 0.14.0, serial_test to 3.4.0
- Add Copy trait to CircuitState enum
- Add Clone derive to CircuitBreaker struct
- Add error trait bounds to CircuitBreakerError generic type
- Update create_rate_limiter return type to use explicit generic parameters
- Fix Go
This commit is contained in:
nutcas3
2026-04-26 00:42:19 +03:00
parent 133523d83b
commit b4b0966937
3 changed files with 16 additions and 12 deletions
+7 -2
View File
@@ -2,7 +2,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::RwLock;
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum CircuitState {
Closed,
Open,
@@ -10,13 +10,17 @@ pub enum CircuitState {
}
#[derive(Debug, thiserror::Error)]
pub enum CircuitBreakerError<E> {
pub enum CircuitBreakerError<E>
where
E: std::error::Error + Send + Sync + 'static,
{
#[error("Circuit breaker is open")]
Open,
#[error("Wrapped error: {0}")]
Inner(#[from] E),
}
#[derive(Clone)]
pub struct CircuitBreaker {
state: Arc<RwLock<CircuitState>>,
failure_count: Arc<RwLock<u32>>,
@@ -39,6 +43,7 @@ impl CircuitBreaker {
pub async fn execute<F, T, E>(&self, operation: F) -> Result<T, CircuitBreakerError<E>>
where
F: std::future::Future<Output = Result<T, E>>,
E: std::error::Error + Send + Sync + 'static,
{
// Check if circuit is open and should attempt to close
self.check_state().await;