fix: delete job time

This commit is contained in:
xtaodada 2023-08-13 13:26:09 +08:00
parent 8eeb844a90
commit c5f23fbdaf
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -1,4 +1,5 @@
import os
from datetime import datetime, timedelta
from apscheduler.schedulers.asyncio import AsyncIOScheduler
@ -10,7 +11,14 @@ async def delete_file(file: str):
os.remove(file)
def add_delete_file_job(file: str, seconds: int = 10 * 60):
def add_delete_file_job(file: str, seconds: int = 60 * 60):
if job := scheduler.get_job(f"df_{file}"):
job.remove()
scheduler.add_job(delete_file, "interval", args=[file], seconds=seconds, id=f"df_{file}")
scheduler.add_job(
delete_file,
"date",
run_date=datetime.now() + timedelta(seconds=seconds),
args=(file,),
id=f"df_{file}",
name=f"df_{file}",
)