Merge branch 'main' into cluster-gemini
# Conflicts: # src/BowongModalFunctions/utils/HTTPUtils.py # src/cluster/video_apps/hls_slice_inference.py
This commit is contained in:
commit
d9c222e4cb
|
|
@ -165,7 +165,7 @@ class GoogleAuthUtils:
|
||||||
timeout: int = 30) -> tuple[dict[Any, Any], int] | tuple[GenerateContentResponse, int]:
|
timeout: int = 30) -> tuple[dict[Any, Any], int] | tuple[GenerateContentResponse, int]:
|
||||||
parameter_model = GoogleAuthUtils.VertexAIRequestModel(contents=contents, generationConfig=config)
|
parameter_model = GoogleAuthUtils.VertexAIRequestModel(contents=contents, generationConfig=config)
|
||||||
json_body = parameter_model.model_dump_json(indent=2, exclude_none=True, by_alias=True,
|
json_body = parameter_model.model_dump_json(indent=2, exclude_none=True, by_alias=True,
|
||||||
exclude={"generation_config": {"safety_settings", "system_instruction"}})
|
exclude={"generation_config": ["safety_settings", "system_instruction"]})
|
||||||
logger.info(json_body)
|
logger.info(json_body)
|
||||||
url = f"{self.gateway_url}/{model_id}:generateContent"
|
url = f"{self.gateway_url}/{model_id}:generateContent"
|
||||||
logger.info(f"Authorization : Bearer {self.access_token}")
|
logger.info(f"Authorization : Bearer {self.access_token}")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
import modal
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
# 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/Hong_Kong")
|
||||||
|
)
|
||||||
|
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小时之前的时间戳
|
||||||
|
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, 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