feat: improve generation analytics and maintenance
This commit is contained in:
29
backend/app/tasks/audio_cache.py
Normal file
29
backend/app/tasks/audio_cache.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Celery tasks for story audio cache maintenance."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from app.core.celery_app import celery_app
|
||||
from app.core.logging import get_logger
|
||||
from app.db.database import _get_session_factory
|
||||
from app.services.story_service import prune_story_audio_cache
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
@celery_app.task
|
||||
def prune_story_audio_cache_task():
|
||||
"""Daily task to prune expired story audio cache files."""
|
||||
logger.info("prune_story_audio_cache_task_started")
|
||||
|
||||
async def _run():
|
||||
session_factory = _get_session_factory()
|
||||
async with session_factory() as session:
|
||||
return await prune_story_audio_cache(session)
|
||||
|
||||
try:
|
||||
result = asyncio.run(_run())
|
||||
logger.info("prune_story_audio_cache_task_completed", **result)
|
||||
return result
|
||||
except Exception as exc:
|
||||
logger.error("prune_story_audio_cache_task_failed", error=str(exc))
|
||||
raise
|
||||
Reference in New Issue
Block a user