LibreTranslate/libretranslate/remove_translated_files.py
copilot-swe-agent[bot] ac0f15a51d Fix CUDA docker timezone issue by explicitly setting UTC timezone in BackgroundScheduler
Co-authored-by: pierotofy <1951843+pierotofy@users.noreply.github.com>
2026-02-07 04:11:45 +00:00

27 lines
781 B
Python

import atexit
import os
import time
from datetime import datetime
from apscheduler.schedulers.background import BackgroundScheduler
def remove_translated_files(upload_dir: str):
now = time.mktime(datetime.now().timetuple())
for f in os.listdir(upload_dir):
f = os.path.join(upload_dir, f)
if os.path.isfile(f):
f_time = os.path.getmtime(f)
if (now - f_time) > 1800: # 30 minutes
os.remove(f)
def setup(upload_dir):
scheduler = BackgroundScheduler(daemon=True, timezone='UTC')
scheduler.add_job(remove_translated_files, "interval", minutes=30, kwargs={'upload_dir': upload_dir})
scheduler.start()
# Shut down the scheduler when exiting the app
atexit.register(lambda: scheduler.shutdown())