From 06bf5c4db75569481de7c14f15113e485c6f32a0 Mon Sep 17 00:00:00 2001 From: GinHa <15201596918@163.com> Date: Wed, 22 Jul 2026 15:15:37 +0800 Subject: [PATCH] =?UTF-8?q?celery=20=E5=8D=87=E7=BA=A7=E5=AE=B9=E7=81=BE?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=86=97=E4=BD=99=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- video-gen-api/app/tasks/cleanup.py | 51 ------------------------------ 1 file changed, 51 deletions(-) delete mode 100644 video-gen-api/app/tasks/cleanup.py diff --git a/video-gen-api/app/tasks/cleanup.py b/video-gen-api/app/tasks/cleanup.py deleted file mode 100644 index 330f5b99..00000000 --- a/video-gen-api/app/tasks/cleanup.py +++ /dev/null @@ -1,51 +0,0 @@ -import asyncio -from datetime import datetime, timedelta - -from app.tasks.celery_app import celery_app - - -@celery_app.task -def cleanup_expired_video_urls(): - """Run hourly. Clear expired video URL tokens.""" - asyncio.run(_cleanup_urls()) - - -async def _cleanup_urls(): - from app.models.base import async_session - from app.models.generation_record import GenerationRecord - from sqlalchemy import update - - async with async_session() as db: - now = datetime.now() - await db.execute( - update(GenerationRecord) - .where( - GenerationRecord.video_url_expires_at.isnot(None), - GenerationRecord.video_url_expires_at < now, - GenerationRecord.deleted_at.is_(None), - ) - .values(video_url_expires_at=None) - ) - await db.commit() - - -@celery_app.task -def cleanup_old_notifications(): - """Run daily. Delete read notifications older than 30 days.""" - asyncio.run(_cleanup_notifications()) - - -async def _cleanup_notifications(): - from app.models.base import async_session - from app.models.notification import Notification - from sqlalchemy import delete - - async with async_session() as db: - cutoff = datetime.now() - timedelta(days=30) - await db.execute( - delete(Notification).where( - Notification.is_read == True, - Notification.created_at < cutoff, - ) - ) - await db.commit()