refactor(registry): 生产环境数据库访问迁移至 SQLx 并统一测试端口策略

将 rusqlite 从生产依赖移至 dev-dependencies,正式数据库操作全部
由 SQLx 完成;rusqlite 仅保留用于测试夹具及旧数据库兼容验证。

UI 验收脚本移除 HTTP 代理和动态端口分配,统一通过
ui-test-port.mjs 的 assertUiPortAvailable 直连 8787 端口,
确保测试与正式实例串行执行。

新增 doc/registry/rust/axum-sqlx-architecture.md 记录模块职责、
数据兼容、退出资源回收及验证维护规范。

修复接收器页面按钮缺少显式 height 导致的布局偏差。
```
This commit is contained in:
2026-10-27 20:04:34 +08:00
parent a68dc50798
commit 281af4fe3d
42 changed files with 2435 additions and 1301 deletions
+20 -15
View File
@@ -1,5 +1,5 @@
//! Bounded accepted-observation feed, independent of browser connections.
use crate::{Worker, geofences::Engine, realtime::TargetStore};
use crate::{lifecycle::Signal, realtime::TargetStore, services::Services};
use axum::{
Router,
extract::State,
@@ -27,7 +27,11 @@ async fn status(State(health): State<Health>, headers: HeaderMap) -> Response {
.insert("cache-control", "no-store".parse().unwrap());
response
}
pub fn start(worker: Worker, live: TargetStore) -> (Router, tokio::task::JoinHandle<()>) {
pub fn start(
services: Services,
live: TargetStore,
stop: Signal,
) -> (Router, tokio::task::JoinHandle<crate::error::Result<()>>) {
let health = Health::default();
let state = health.clone();
let (tx, mut rx) = tokio::sync::mpsc::channel(4096);
@@ -45,10 +49,12 @@ pub fn start(worker: Worker, live: TargetStore) -> (Router, tokio::task::JoinHan
let mut interval = tokio::time::interval(std::time::Duration::from_millis(250));
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
loop {
interval.tick().await;
tokio::select! {_=stop.cancelled()=>{},_=interval.tick()=>{}}
if pending.is_none() {
let now = crate::realtime::now_ms();
let Ok(mut store) = live.lock() else { break };
let Ok(mut store) = live.lock() else {
return Err("实时存储不可用".into());
};
store.expire(now);
let mut observations = Vec::new();
while let Ok(o) = rx.try_recv() {
@@ -57,16 +63,8 @@ pub fn start(worker: Worker, live: TargetStore) -> (Router, tokio::task::JoinHan
pending = Some((observations, store.frame(None, now).targets, now));
}
let (observations, active, now) = pending.clone().unwrap_or_default();
let current = engine.clone();
let result = worker
.run(move |s| {
let mut engine = match current {
Some(e) => e,
None => Engine::restore(&s.db)?,
};
engine.process(&mut s.db, &observations, &active, now)?;
Ok(engine)
})
let result = services
.monitor(engine.clone(), &observations, &active, now)
.await;
match result {
Ok(next) => {
@@ -76,13 +74,20 @@ pub fn start(worker: Worker, live: TargetStore) -> (Router, tokio::task::JoinHan
*error = None;
}
}
Err(_) => {
Err(error) => {
if stop.is_cancelled() {
return Err(error);
}
if let Ok(mut error) = state.error.lock() {
*error = Some("告警保存失败,正在重试;请检查数据库和磁盘");
}
}
}
if stop.is_cancelled() && pending.is_none() && rx.is_empty() {
break;
}
}
Ok(())
});
(
Router::new()