mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-12 23:15:14 +00:00
feat: Add list_rating_plans error handling, dead_code attributes, and refactor monitoring/models
- Add error mapping to list_rating_plans in engine.rs - Add dead_code attributes to get/list_map/deactivate methods in rating_plans_repo and row_to_plan function - Add list method to RatingPlansRepo returning Vec<RatingPlan> - Add dead_code attribute to validate_imsi in helpers - Add UsageBlocked and ConfigurationError variants to ChargingError with Display/IntoResponse implementations - Add Default
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use tracing::{info, debug};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::errors::{ChargingError, ChargingResult, ErrorContext};
|
||||
use super::types::{SystemStats, HealthStatus};
|
||||
use crate::errors::ChargingResult;
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl crate::charging::ChargingEngine {
|
||||
@@ -130,16 +129,6 @@ impl crate::charging::ChargingEngine {
|
||||
let last_error: Option<String> = redis::AsyncCommands::get(&mut conn, "last_error").await.unwrap_or(None);
|
||||
Ok(last_error)
|
||||
}
|
||||
|
||||
async fn get_uptime(&self) -> ChargingResult<u64> {
|
||||
match self.startup_time.elapsed() {
|
||||
Ok(duration) => Ok(duration.as_secs()),
|
||||
Err(_) => Ok(std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use tokio::time::interval;
|
||||
use tracing::{info, warn, error, debug};
|
||||
use chrono::Datelike;
|
||||
|
||||
use crate::errors::{ChargingResult, log_error};
|
||||
use crate::monitoring::types::{SystemStats, HealthStatus};
|
||||
@@ -144,7 +145,7 @@ impl crate::charging::ChargingEngine {
|
||||
let processed = self.apply_monthly_fees().await?;
|
||||
|
||||
// Update last fee timestamp
|
||||
let _: () = redis::AsyncCommands::set(&mut conn, last_fee_key, current_month).await.unwrap_or(());
|
||||
let _: () = redis::AsyncCommands::set(&mut conn, last_fee_key, ¤t_month).await.unwrap_or(());
|
||||
|
||||
info!("Applied monthly fees to {} accounts for {}", processed, current_month);
|
||||
Ok(())
|
||||
@@ -155,9 +156,12 @@ impl crate::charging::ChargingEngine {
|
||||
.map_err(|e| crate::errors::ChargingError::RedisConnection(e.to_string()))?;
|
||||
|
||||
let active_sessions: u64 = redis::AsyncCommands::get(&mut conn, "stats:active_sessions").await.unwrap_or(0);
|
||||
let total_accounts: u64 = redis::AsyncCommands::keys(&mut conn, "account:*").await.unwrap_or_default().len() as u64;
|
||||
let blocked_users: u64 = redis::AsyncCommands::keys(&mut conn, "block:*").await.unwrap_or_default().len() as u64;
|
||||
let low_balance_alerts: u64 = redis::AsyncCommands::keys(&mut conn, "alert:low_balance:*").await.unwrap_or_default().len() as u64;
|
||||
let account_keys: Vec<String> = redis::AsyncCommands::keys(&mut conn, "account:*").await.unwrap_or_default();
|
||||
let total_accounts: u64 = account_keys.len() as u64;
|
||||
let block_keys: Vec<String> = redis::AsyncCommands::keys(&mut conn, "block:*").await.unwrap_or_default();
|
||||
let blocked_users: u64 = block_keys.len() as u64;
|
||||
let alert_keys: Vec<String> = redis::AsyncCommands::keys(&mut conn, "alert:low_balance:*").await.unwrap_or_default();
|
||||
let low_balance_alerts: u64 = alert_keys.len() as u64;
|
||||
|
||||
let stats = SystemStats {
|
||||
active_sessions,
|
||||
@@ -170,7 +174,7 @@ impl crate::charging::ChargingEngine {
|
||||
Ok(stats)
|
||||
}
|
||||
|
||||
async fn get_uptime(&self) -> ChargingResult<u64> {
|
||||
pub async fn get_uptime(&self) -> ChargingResult<u64> {
|
||||
// Calculate actual uptime since startup
|
||||
match self.startup_time.elapsed() {
|
||||
Ok(duration) => Ok(duration.as_secs()),
|
||||
|
||||
Reference in New Issue
Block a user