mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-27 22:38:47 +00:00
refactor: Fix Rust edition, remove duplicate lint rule, and improve error handling in charging-engine and packet-gateway
- Change Rust edition from "2026" to "2024" in workspace Cargo.toml - Remove duplicate expect_used lint rule from workspace lints - Prefix unused account variable with underscore in calculate_usage_cost - Split CARGO_MANIFEST_DIR assignment into separate variable in run_migrations - Clone plan_id before moving plan in add_rating_plan handler - Replace expect() with unwrap() in governor
This commit is contained in:
+1
-2
@@ -8,7 +8,7 @@ resolver = "2"
|
|||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
authors = ["TaaS Team <[email protected]>"]
|
authors = ["TaaS Team <[email protected]>"]
|
||||||
edition = "2026"
|
edition = "2024"
|
||||||
rust-version = "1.94"
|
rust-version = "1.94"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
@@ -27,7 +27,6 @@ unwrap_used = "deny"
|
|||||||
expect_used = "deny"
|
expect_used = "deny"
|
||||||
panic = "deny"
|
panic = "deny"
|
||||||
unwrap_in_result = "deny"
|
unwrap_in_result = "deny"
|
||||||
expect_used = "deny"
|
|
||||||
unimplemented = "deny"
|
unimplemented = "deny"
|
||||||
todo = "warn"
|
todo = "warn"
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::errors::{ChargingError, ChargingResult, validate_amount};
|
|||||||
impl super::ChargingEngine {
|
impl super::ChargingEngine {
|
||||||
pub async fn calculate_usage_cost(&self, event: &UsageEvent) -> ChargingResult<f64> {
|
pub async fn calculate_usage_cost(&self, event: &UsageEvent) -> ChargingResult<f64> {
|
||||||
// Get subscriber account to determine rating plan
|
// Get subscriber account to determine rating plan
|
||||||
let account = self.get_subscriber_account(&event.imsi).await?;
|
let _account = self.get_subscriber_account(&event.imsi).await?;
|
||||||
|
|
||||||
// Get rating plan from Postgres (simplified - defaults to basic).
|
// Get rating plan from Postgres (simplified - defaults to basic).
|
||||||
let plan = self
|
let plan = self
|
||||||
|
|||||||
@@ -245,7 +245,8 @@ async fn run_migrations(database_url: &str) -> Result<(), Box<dyn std::error::Er
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
// Change to repo root to find migrations directory
|
// Change to repo root to find migrations directory
|
||||||
let repo_root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
let manifest_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
let repo_root = manifest_dir
|
||||||
.parent()
|
.parent()
|
||||||
.and_then(|p| p.parent())
|
.and_then(|p| p.parent())
|
||||||
.ok_or("Failed to determine repo root")?;
|
.ok_or("Failed to determine repo root")?;
|
||||||
|
|||||||
@@ -66,12 +66,13 @@ pub async fn add_rating_plan(
|
|||||||
sms_limit: req.get("sms_limit").and_then(|v| v.as_u64()).unwrap_or(100),
|
sms_limit: req.get("sms_limit").and_then(|v| v.as_u64()).unwrap_or(100),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let plan_id = plan.plan_id.clone();
|
||||||
state.charging_engine.add_rating_plan(plan).await
|
state.charging_engine.add_rating_plan(plan).await
|
||||||
.with_context("Failed to add rating plan")?;
|
.with_context("Failed to add rating plan")?;
|
||||||
|
|
||||||
Ok(Json(serde_json::json!({
|
Ok(Json(serde_json::json!({
|
||||||
"status": "added",
|
"status": "added",
|
||||||
"plan_id": plan.plan_id,
|
"plan_id": plan_id,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,17 +33,17 @@ pub fn create_router(state: AppState) -> Router {
|
|||||||
.and_then(|s| s.parse().ok())
|
.and_then(|s| s.parse().ok())
|
||||||
.unwrap_or(20);
|
.unwrap_or(20);
|
||||||
|
|
||||||
|
// Build governor config, fallback to default if None
|
||||||
let governor_conf = GovernorConfigBuilder::default()
|
let governor_conf = GovernorConfigBuilder::default()
|
||||||
.per_second(requests_per_second as u64)
|
.per_second(requests_per_second as u64)
|
||||||
.burst_size(burst_size)
|
.burst_size(burst_size)
|
||||||
.finish()
|
.finish()
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|| {
|
||||||
// Fallback to default config if builder fails
|
|
||||||
GovernorConfigBuilder::default()
|
GovernorConfigBuilder::default()
|
||||||
.per_second(10)
|
.per_second(10)
|
||||||
.burst_size(20)
|
.burst_size(20)
|
||||||
.finish()
|
.finish()
|
||||||
.expect("Default governor config should never fail")
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
Router::new()
|
Router::new()
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ async fn main() -> Result<()> {
|
|||||||
info!("Connected to Redis successfully");
|
info!("Connected to Redis successfully");
|
||||||
|
|
||||||
// Initialize charging engine client
|
// Initialize charging engine client
|
||||||
let charging_client = ChargingEngineClient::new(&args.charging_engine_url);
|
let charging_client = ChargingEngineClient::new(args.charging_engine_url.clone());
|
||||||
info!("Charging engine client initialized");
|
info!("Charging engine client initialized");
|
||||||
|
|
||||||
#[cfg(feature = "ebpf")]
|
#[cfg(feature = "ebpf")]
|
||||||
@@ -167,9 +167,9 @@ async fn main() -> Result<()> {
|
|||||||
info!("Health check server listening on {}", addr);
|
info!("Health check server listening on {}", addr);
|
||||||
|
|
||||||
let listener = tokio::net::TcpListener::bind(&addr).await
|
let listener = tokio::net::TcpListener::bind(&addr).await
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to bind health check server: {}", e))?;
|
.expect("Failed to bind health check server");
|
||||||
axum::serve(listener, app).await
|
axum::serve(listener, app).await
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to start health check server: {}", e))?;
|
.expect("Failed to start health check server");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Main synchronization loop with graceful shutdown
|
// Main synchronization loop with graceful shutdown
|
||||||
|
|||||||
Reference in New Issue
Block a user