"""Background task utilities for long-running operations.""" import asyncio from collections.abc import Callable class BackgroundTasks: """Simple background task manager using FastAPI BackgroundTasks.""" @staticmethod async def run_in_background(func: Callable, *args, **kwargs): """ Run function in background. For now, uses asyncio to run tasks in background. In production, consider Celery or similar for distributed tasks. Args: func: Function to run *args: Positional arguments **kwargs: Keyword arguments """ asyncio.create_task(func(*args, **kwargs)) async def generate_thumbnails_task(image_id: str, storage_path: str, contents: bytes): """ Background task to generate thumbnails. Args: image_id: Image ID storage_path: Original image storage path contents: Image file contents """ from uuid import UUID from app.images.processing import generate_thumbnails # Generate thumbnails generate_thumbnails(UUID(image_id), storage_path, contents) # Update image metadata with thumbnail paths # This would require database access - for now, thumbnails are generated synchronously pass