fix: 通过log记录清理任务
This commit is contained in:
parent
8263b22346
commit
38d594b4e9
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in New Issue