whole process
This commit is contained in:
@@ -750,6 +750,28 @@ def remove_sqlite_database_files(settings: Settings) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def reset_delivery_client_progress(settings: Settings) -> None:
|
||||
"""仅重置客户端投递游标(保留历史快照与 watch 缓存)。"""
|
||||
init_db(settings)
|
||||
conn = _connect(settings.sqlite_path)
|
||||
try:
|
||||
# 清空所有客户端游标,避免沿用旧 client_id 的消费进度。
|
||||
conn.execute("UPDATE delivery_client_cursor SET last_delivered_id = 0")
|
||||
# 确保默认客户端行存在(历史库升级场景)。
|
||||
for kind in ("measure", "health"):
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO delivery_client_cursor (client_id, kind, last_delivered_id)
|
||||
VALUES (?, ?, 0)
|
||||
ON CONFLICT(client_id, kind) DO NOTHING
|
||||
""",
|
||||
(DEFAULT_CLIENT_ID, kind),
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def clear_watch_cache_and_snapshots(settings: Settings) -> None:
|
||||
"""清空 watch 已处理路径与对应快照,便于重新跑推理(与 measure/action_watch 的 use_state_file 开关一致)。"""
|
||||
init_db(settings)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""启动前清空状态:SQLite(客户端数据)、watch 旧 JSON。
|
||||
"""启动前清空状态:默认仅重置客户端游标,保留 SQLite 历史快照。
|
||||
|
||||
由 start_fresh.sh 在 uvicorn 之前调用。
|
||||
- 默认保留 SQLite 历史数据,仅重置 client_id 投递游标(fresh 语义)
|
||||
- 设置 CLEAR_SQLITE_DATABASE=1 可强制清空 SQLite(主库 + wal/shm)
|
||||
- 默认保留 measure_output 以复用中间步骤(点云等)
|
||||
- 设置 CLEAR_MEASURE_OUTPUT=1 清空测量输出目录
|
||||
- 设置 CLEAR_ACTION_OUTPUT=1 清空行为输出目录
|
||||
@@ -11,7 +13,7 @@ from __future__ import annotations
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from app.db import _safe_rm_tree, remove_sqlite_database_files
|
||||
from app.db import _safe_rm_tree, remove_sqlite_database_files, reset_delivery_client_progress
|
||||
from app.settings import get_settings
|
||||
|
||||
|
||||
@@ -29,12 +31,23 @@ def _rm_legacy_json(path: Path | None) -> None:
|
||||
def run_prestart_fresh() -> None:
|
||||
s = get_settings()
|
||||
|
||||
# 始终清空 SQLite(客户端数据)
|
||||
remove_sqlite_database_files(s)
|
||||
print(
|
||||
f"[prestart-fresh] removed SQLite at {s.sqlite_path} (and -wal/-shm if present).",
|
||||
flush=True,
|
||||
clear_sqlite_database = os.environ.get("CLEAR_SQLITE_DATABASE", "").strip() in (
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
)
|
||||
if clear_sqlite_database:
|
||||
remove_sqlite_database_files(s)
|
||||
print(
|
||||
f"[prestart-fresh] removed SQLite at {s.sqlite_path} (and -wal/-shm if present).",
|
||||
flush=True,
|
||||
)
|
||||
else:
|
||||
reset_delivery_client_progress(s)
|
||||
print(
|
||||
f"[prestart-fresh] kept SQLite history, reset delivery client progress in {s.sqlite_path}.",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
# 检查是否清空中间输出目录(默认保留以复用点云等中间步骤)
|
||||
clear_measure_output = os.environ.get("CLEAR_MEASURE_OUTPUT", "").strip() in ("1", "true", "yes")
|
||||
|
||||
Reference in New Issue
Block a user