feat(fish_api): SQLite 快照投递、日志与 watch 空闲告警

- 新增 SQLite:measure/health 快照、delivery_cursor 单消费者 pop;clear/start_fresh 可清空库
- biomass GET 仅返回约定 data 字段,X-Fish-Biomass-New 表示是否有新快照;poller 读响应头
- loguru 桥接 uvicorn,子进程 stdout 流式输出;format_json_pretty 与算法摘要日志
- measure/action watch 无新任务时限流 WARNING;watch_idle 共用逻辑
- 依赖 loguru;新增 db、logging_config、subprocess_run、watch_idle、启动脚本

FishMeasure: 更新 fish_video_weight_evaluation 与 predict_weigth_from_svo2;移除未用 refbox/segmentation 脚本
Made-with: Cursor
This commit is contained in:
zaiun xu
2026-04-09 11:54:30 +08:00
parent db181d4f84
commit 5e1b2117c1
29 changed files with 1464 additions and 1714 deletions

View File

@@ -0,0 +1,41 @@
"""子进程运行并把 stdout/stderr 流式写入 loguru便于查看 FishMeasure / FishAction 中间输出。"""
from __future__ import annotations
import os
import subprocess
from typing import Dict, List, Optional
from loguru import logger
def run_subprocess_with_log(
cmd: List[str],
*,
cwd: str,
env: Optional[Dict[str, str]] = None,
log_name: str,
) -> subprocess.CompletedProcess[str]:
"""运行子进程,合并 stderr 到 stdout按行输出到 loguru。
返回 CompletedProcessstdout 为完整输出,便于失败时拼进异常信息。
"""
proc = subprocess.Popen(
cmd,
cwd=cwd,
env=env if env is not None else os.environ.copy(),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
)
lines: List[str] = []
if proc.stdout is not None:
for line in proc.stdout:
lines.append(line)
s = line.rstrip()
if s:
logger.info("[{}] {}", log_name, s)
rc = proc.wait()
out = "".join(lines)
return subprocess.CompletedProcess(cmd, rc, out, "")