1
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
from celery import Celery
|
||||
from app.config import settings
|
||||
|
||||
if settings.REDIS_URL:
|
||||
celery_app = Celery("videogen")
|
||||
celery_app.conf.update(
|
||||
broker_url=settings.REDIS_URL.replace("/0", "/1"),
|
||||
result_backend=settings.REDIS_URL.replace("/0", "/2"),
|
||||
task_serializer="json",
|
||||
accept_content=["json"],
|
||||
task_soft_time_limit=600,
|
||||
task_time_limit=900,
|
||||
worker_prefetch_multiplier=1,
|
||||
)
|
||||
celery_app.autodiscover_tasks(["app.tasks"])
|
||||
else:
|
||||
celery_app = None
|
||||
@@ -0,0 +1,50 @@
|
||||
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,
|
||||
)
|
||||
.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()
|
||||
@@ -0,0 +1,2 @@
|
||||
# Video generation is now handled by app.services.video_queue
|
||||
# This file is kept as an empty shell to avoid import errors.
|
||||
Reference in New Issue
Block a user