采用定时任务每天3 AM 香港时间清理过期的直播缓存
* 采用定时任务每天3 AM 香港时间清理过期的直播缓存 --------- Merge request URL: https://g-ldyi2063.coding.net/p/dev/d/modalDeploy/git/merge/4868?initial=true Co-authored-by: shuohigh@gmail.com
This commit is contained in:
parent
976f213cbb
commit
11e2cd3454
|
|
@ -0,0 +1,35 @@
|
|||
import shutil
|
||||
|
||||
import modal
|
||||
|
||||
from ..ffmpeg_app import ffmpeg_worker_image, app, config, s3_mount, local_copy_to_s3, output_path_prefix
|
||||
|
||||
with ffmpeg_worker_image.imports():
|
||||
import os, time
|
||||
from datetime import datetime
|
||||
|
||||
hls_recording_volume = modal.Volume.from_name("stream_records", create_if_missing=True)
|
||||
hls_recording_mount_point = "/mnt/stream_records"
|
||||
|
||||
|
||||
# runs daily at 3 am (Hong Kong time)
|
||||
@app.function(
|
||||
volumes={hls_recording_mount_point: hls_recording_volume},
|
||||
schedule=modal.Cron("0 3 * * *", timezone="Asia/HongKong")
|
||||
)
|
||||
def storage_cleanup():
|
||||
# todo: clean up storage
|
||||
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 = []
|
||||
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)))
|
||||
|
||||
for folder in old_folders:
|
||||
shutil.rmtree(folder)
|
||||
Loading…
Reference in New Issue