From 38d594b4e9d4cb9938928854be2b01d9addfd032 Mon Sep 17 00:00:00 2001 From: "shuohigh@gmail.com" Date: Wed, 25 Jun 2025 10:38:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=9A=E8=BF=87log=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=B8=85=E7=90=86=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cluster/ffmpeg_apps/schedule_cleanup.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cluster/ffmpeg_apps/schedule_cleanup.py b/src/cluster/ffmpeg_apps/schedule_cleanup.py index f3d0900..0075d97 100644 --- a/src/cluster/ffmpeg_apps/schedule_cleanup.py +++ b/src/cluster/ffmpeg_apps/schedule_cleanup.py @@ -1,12 +1,13 @@ -import shutil - import modal -from ..ffmpeg_app import ffmpeg_worker_image, app, config, s3_mount, local_copy_to_s3, output_path_prefix +from ..ffmpeg_app import ffmpeg_worker_image, app, config with ffmpeg_worker_image.imports(): import os, time from datetime import datetime + from loguru import logger + import shutil + from typing import Tuple, List hls_recording_volume = modal.Volume.from_name("stream_records", create_if_missing=True) hls_recording_mount_point = "/mnt/stream_records" @@ -20,15 +21,19 @@ with ffmpeg_worker_image.imports(): def storage_cleanup(): output_dir = f"{config.modal_environment}/records/hls/" volume_output_dir = f"{hls_recording_mount_point}/{output_dir}" - now = time.time() cutoff = now - 24 * 60 * 60 # 24小时之前的时间戳 - old_folders = [] + new_folders: List[Tuple[str, datetime]] = [] + old_folders: List[Tuple[str, datetime]] = [] for entry in os.scandir(volume_output_dir): if entry.is_dir(): mtime = entry.stat().st_mtime if mtime < cutoff: old_folders.append((entry.path, datetime.fromtimestamp(mtime))) + else: + new_folders.append((entry.path, datetime.fromtimestamp(mtime))) - for folder in old_folders: + for folder, timestamp in old_folders: + logger.info(f"Removing {folder}, last modified {timestamp.isoformat()}") shutil.rmtree(folder) + logger.info(f"{len(old_folders)} tasks cleaned up, {len(new_folders)} tasks remaining")