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:
iven
2026-04-11 01:19:30 +08:00
parent 5901ee82f0
commit 810eef769f
9 changed files with 216 additions and 30 deletions

View 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))
}

View File

@@ -0,0 +1 @@
pub mod health;