misskey2telegram/models/services/scheduler.py
2023-08-12 11:36:51 +08:00

17 lines
440 B
Python

import os
from apscheduler.schedulers.asyncio import AsyncIOScheduler
scheduler = AsyncIOScheduler(timezone="Asia/ShangHai")
async def delete_file(file: str):
if os.path.exists(file):
os.remove(file)
def add_delete_file_job(file: str, seconds: int = 10 * 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}")