feat: 配置写死与 baked 模块,Alembic 建表,百度仅 BAIDU_*

- 新增 app/baked/algorithm|pipeline,非部署参数不再走 env;Settings 保留 DB/HTTP/RTSP/海康/百度/MinIO/Demo
- 移除 init_db_schema 与 reload 配置;main 仅 check_database;start*.sh 在 uvicorn 前执行 alembic upgrade head
- 依赖 psycopg[binary] 供 Alembic 同步 URL;alembic/env 注释与预发清单更新
- 撕段门控消费管线、各视频/语音/归档调用改为 baked
- 百度环境变量仅 BAIDU_APP_ID、BAIDU_API_KEY、BAIDU_SECRET_KEY 与 BAIDU_* 超时/ASR;人脸脚本与 baidu_speech 文案同步
- 全量单测与 .env.example 更新;.gitignore 忽略 refs/(本地权重/视频不入库)

Made-with: Cursor
This commit is contained in:
Kevin
2026-04-24 15:33:22 +08:00
parent b651364877
commit 8a4bad99d3
47 changed files with 1333 additions and 648 deletions

View File

@@ -22,7 +22,7 @@ from typing import TYPE_CHECKING
from loguru import logger
from sqlalchemy.ext.asyncio import async_sessionmaker
from app.config import Settings
from app.baked import pipeline as bp
from app.domain.consumption import SurgeryConsumptionStored
if TYPE_CHECKING:
@@ -86,11 +86,9 @@ class ArchivePersister:
def __init__(
self,
*,
settings: Settings,
repository: "SurgeryResultRepository | None",
session_factory: async_sessionmaker,
) -> None:
self._s = settings
self._repo = repository
self._session_factory = session_factory
self._archive: dict[str, _ArchiveEntry] = {}
@@ -139,7 +137,7 @@ class ArchivePersister:
if await self._write_to_db(surgery_id, details):
return True
entry = _ArchiveEntry(details=list(details))
if self._s.archive_persist_durable_fallback_enabled:
if bp.ARCHIVE_PERSIST_DURABLE_FALLBACK_ENABLED:
entry.durable_path = self._write_durable(surgery_id, details)
async with self._lock:
self._archive[surgery_id] = entry
@@ -193,9 +191,9 @@ class ArchivePersister:
async def recover_from_durable_fallback(self) -> int:
"""进程启动时调用:从 durable 目录把未写库的归档读回内存。"""
if not self._s.archive_persist_durable_fallback_enabled:
if not bp.ARCHIVE_PERSIST_DURABLE_FALLBACK_ENABLED:
return 0
directory = Path(self._s.archive_persist_durable_fallback_dir)
directory = Path(bp.ARCHIVE_PERSIST_DURABLE_FALLBACK_DIR)
if not directory.exists():
return 0
loaded = 0
@@ -250,7 +248,7 @@ class ArchivePersister:
surgery_id: str,
details: list[SurgeryConsumptionStored],
) -> Path | None:
directory = Path(self._s.archive_persist_durable_fallback_dir)
directory = Path(bp.ARCHIVE_PERSIST_DURABLE_FALLBACK_DIR)
try:
directory.mkdir(parents=True, exist_ok=True)
except Exception as exc:
@@ -281,15 +279,15 @@ class ArchivePersister:
logger.debug("remove durable archive {} failed: {}", path, exc)
def _next_backoff_seconds(self, attempts: int) -> float:
base = float(self._s.archive_persist_retry_interval_seconds)
cap = float(self._s.archive_persist_backoff_cap_seconds)
base = float(bp.ARCHIVE_PERSIST_RETRY_INTERVAL_SECONDS)
cap = float(bp.ARCHIVE_PERSIST_BACKOFF_CAP_SECONDS)
# 指数退避base * 2^(attempts-1),首个间隔即 base。
exp = max(0, attempts - 1)
return min(cap, base * (2**exp))
async def _retry_loop(self) -> None:
base = float(self._s.archive_persist_retry_interval_seconds)
max_attempts = int(self._s.archive_persist_max_retries)
base = float(bp.ARCHIVE_PERSIST_RETRY_INTERVAL_SECONDS)
max_attempts = int(bp.ARCHIVE_PERSIST_MAX_RETRIES)
while not self._retry_stop.is_set():
try:
await asyncio.wait_for(self._retry_stop.wait(), timeout=base)