feat(server): integrate AppState, ModuleRegistry, health check, and graceful shutdown
- Add AppState with DB, Config, EventBus, ModuleRegistry via Axum State - ModuleRegistry now uses Arc for Clone support, builder-pattern register() - Add /api/v1/health endpoint returning status, version, registered modules - Add graceful shutdown on CTRL+C / SIGTERM - erp-common utils: ID generation, timestamp helpers, code generator with tests - Config structs now derive Clone for state sharing - Update wiki to reflect Phase 1 completion
This commit is contained in:
36
crates/erp-server/src/handlers/health.rs
Normal file
36
crates/erp-server/src/handlers/health.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use axum::extract::State;
|
||||
use axum::response::Json;
|
||||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct HealthResponse {
|
||||
pub status: String,
|
||||
pub version: String,
|
||||
pub modules: Vec<String>,
|
||||
}
|
||||
|
||||
/// GET /api/v1/health
|
||||
///
|
||||
/// 服务健康检查,返回运行状态和已注册模块列表
|
||||
pub async fn health_check(State(state): State<AppState>) -> Json<HealthResponse> {
|
||||
let modules = state
|
||||
.module_registry
|
||||
.modules()
|
||||
.iter()
|
||||
.map(|m| m.name().to_string())
|
||||
.collect();
|
||||
|
||||
Json(HealthResponse {
|
||||
status: "ok".to_string(),
|
||||
version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
modules,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn health_check_router() -> Router<AppState> {
|
||||
Router::new().route("/api/v1/health", get(health_check))
|
||||
}
|
||||
1
crates/erp-server/src/handlers/mod.rs
Normal file
1
crates/erp-server/src/handlers/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod health;
|
||||
Reference in New Issue
Block a user