mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2025-05-04 20:30:39 +00:00
app->libretranslate; mv tests/ inside libretranslate/
This commit is contained in:
parent
40a1141eac
commit
a23a9fbd75
47 changed files with 24 additions and 25 deletions
26
libretranslate/remove_translated_files.py
Normal file
26
libretranslate/remove_translated_files.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
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)
|
||||
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())
|
Loading…
Add table
Add a link
Reference in a new issue