From 580e3c0d3bdac939b8d2ae74351461d320e5d60e Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 22 May 2026 11:17:20 +0800 Subject: [PATCH] remove dead code --- backend/app/baked/pipeline.py | 3 +- backend/app/routers/recording_demo.py | 5 ++++ backend/app/services/video_batch_cleanup.py | 33 +++++++++++++++++++++ backend/main.py | 12 ++++++-- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/backend/app/baked/pipeline.py b/backend/app/baked/pipeline.py index abc5eeb..ffb7449 100644 --- a/backend/app/baked/pipeline.py +++ b/backend/app/baked/pipeline.py @@ -41,5 +41,6 @@ VOICE_FILE_LOG_PATH: str = "logs/voice_{surgery_id}.txt" VOICE_UPLOAD_MAX_BYTES: int = 10 * 1024 * 1024 VOICE_CONFIRM_MAX_FAILED_PARSE_ROUNDS: int = 2 -# --- 非实时 batch 标注视频临时保留(小时)--- +# --- 非实时 batch 标注视频 / digest 级 pipeline 输入临时保留(小时)--- VIDEO_BATCH_VIS_TTL_HOURS: int = 24 +VIDEO_BATCH_PIPELINE_INPUT_TTL_HOURS: int = 24 diff --git a/backend/app/routers/recording_demo.py b/backend/app/routers/recording_demo.py index 01e68fc..ec8c96a 100644 --- a/backend/app/routers/recording_demo.py +++ b/backend/app/routers/recording_demo.py @@ -26,6 +26,7 @@ from app.baked import pipeline as bp from app.services.synthetic_rtsp import SyntheticRtspManager from app.services.video_batch_cleanup import ( purge_batch_artifacts, + purge_expired_pipeline_inputs, purge_expired_visualizations, purge_surgery_batch_tree, stage_visualization_pending, @@ -75,6 +76,10 @@ def _background_finalize_visualization( runner.root_dir, ttl_hours=float(bp.VIDEO_BATCH_VIS_TTL_HOURS), ) + purge_expired_pipeline_inputs( + runner.root_dir, + ttl_hours=float(bp.VIDEO_BATCH_PIPELINE_INPUT_TTL_HOURS), + ) class OfflineBatchResponse(BaseModel): diff --git a/backend/app/services/video_batch_cleanup.py b/backend/app/services/video_batch_cleanup.py index 275e36e..0bd908d 100644 --- a/backend/app/services/video_batch_cleanup.py +++ b/backend/app/services/video_batch_cleanup.py @@ -165,3 +165,36 @@ def purge_expired_visualizations(root_dir: Path, *, ttl_hours: float = 24.0) -> if removed: logger.info("video batch visualization TTL sweep removed {} file(s)", removed) return removed + + +def purge_expired_pipeline_inputs(root_dir: Path, *, ttl_hours: float = 24.0) -> int: + """Delete ``cache/{digest}/input/pipeline*`` older than *ttl_hours*.""" + + cache_root = root_dir / "cache" + if not cache_root.is_dir(): + return 0 + + cutoff = time.time() - float(ttl_hours) * 3600.0 + removed = 0 + for digest_dir in cache_root.iterdir(): + if not digest_dir.is_dir(): + continue + input_dir = digest_dir / "input" + if not input_dir.is_dir(): + continue + for pipeline_file in input_dir.glob("pipeline*"): + if not pipeline_file.is_file(): + continue + try: + if pipeline_file.stat().st_mtime >= cutoff: + continue + except OSError: + continue + pipeline_file.unlink(missing_ok=True) + removed += 1 + logger.info("purged expired pipeline input {}", pipeline_file) + _prune_empty_parents(input_dir, stop_at=cache_root) + + if removed: + logger.info("video batch pipeline input TTL sweep removed {} file(s)", removed) + return removed diff --git a/backend/main.py b/backend/main.py index 890e60d..9387ef9 100644 --- a/backend/main.py +++ b/backend/main.py @@ -50,14 +50,22 @@ async def lifespan(app: FastAPI): "Database connection verified; ensure schema is applied with `alembic upgrade head` before serving traffic" ) from app.baked import pipeline as bp - from app.services.video_batch_cleanup import purge_expired_visualizations + from app.services.video_batch_cleanup import ( + purge_expired_pipeline_inputs, + purge_expired_visualizations, + ) from app.algo_host.batch_service import BatchAlgorithmService repo_root = Path(__file__).resolve().parent + batch_root = BatchAlgorithmService(root_dir=repo_root / "logs" / "video_batch").root_dir purge_expired_visualizations( - BatchAlgorithmService(root_dir=repo_root / "logs" / "video_batch").root_dir, + batch_root, ttl_hours=float(bp.VIDEO_BATCH_VIS_TTL_HOURS), ) + purge_expired_pipeline_inputs( + batch_root, + ttl_hours=float(bp.VIDEO_BATCH_PIPELINE_INPUT_TTL_HOURS), + ) container = build_container(settings) app.state.container = container await container.start()