phase 5
This commit is contained in:
@@ -28,6 +28,14 @@ class StorageClient:
|
||||
self.bucket = settings.MINIO_BUCKET
|
||||
self._ensure_bucket_exists()
|
||||
|
||||
def put_object(self, bucket_name: str, object_name: str, data: BinaryIO, length: int, content_type: str):
|
||||
"""MinIO-compatible put_object method."""
|
||||
return self.upload_file(data, object_name, content_type)
|
||||
|
||||
def remove_object(self, bucket_name: str, object_name: str):
|
||||
"""MinIO-compatible remove_object method."""
|
||||
return self.delete_file(object_name)
|
||||
|
||||
def _ensure_bucket_exists(self) -> None:
|
||||
"""Create bucket if it doesn't exist."""
|
||||
try:
|
||||
@@ -116,3 +124,19 @@ class StorageClient:
|
||||
|
||||
# Global storage client instance
|
||||
storage_client = StorageClient()
|
||||
|
||||
|
||||
def get_storage_client() -> StorageClient:
|
||||
"""Get the global storage client instance."""
|
||||
return storage_client
|
||||
|
||||
|
||||
# Compatibility methods for MinIO-style API
|
||||
def put_object(bucket_name: str, object_name: str, data: BinaryIO, length: int, content_type: str):
|
||||
"""MinIO-compatible put_object method."""
|
||||
storage_client.upload_file(data, object_name, content_type)
|
||||
|
||||
|
||||
def remove_object(bucket_name: str, object_name: str):
|
||||
"""MinIO-compatible remove_object method."""
|
||||
storage_client.delete_file(object_name)
|
||||
|
||||
44
backend/app/core/tasks.py
Normal file
44
backend/app/core/tasks.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user