feat: add storage cleanup mechanism with soft delete and auto scheduler
- Add soft delete (deleted_at column) to preserve task records for statistics - Implement cleanup service to delete old files while keeping DB records - Add automatic cleanup scheduler (configurable interval, default 24h) - Add admin endpoints: storage stats, cleanup trigger, scheduler status - Update task service with admin views (include deleted/files_deleted) - Add frontend storage management UI in admin dashboard - Add i18n translations for storage management 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -216,6 +216,15 @@ async def lifespan(app: FastAPI):
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to initialize prediction semaphore: {e}")
|
||||
|
||||
# Initialize cleanup scheduler if enabled
|
||||
if settings.cleanup_enabled:
|
||||
try:
|
||||
from app.services.cleanup_scheduler import start_cleanup_scheduler
|
||||
await start_cleanup_scheduler()
|
||||
logger.info("Cleanup scheduler initialized")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to initialize cleanup scheduler: {e}")
|
||||
|
||||
logger.info("Application startup complete")
|
||||
|
||||
yield
|
||||
@@ -223,6 +232,15 @@ async def lifespan(app: FastAPI):
|
||||
# Shutdown
|
||||
logger.info("Shutting down Tool_OCR application...")
|
||||
|
||||
# Stop cleanup scheduler
|
||||
if settings.cleanup_enabled:
|
||||
try:
|
||||
from app.services.cleanup_scheduler import stop_cleanup_scheduler
|
||||
await stop_cleanup_scheduler()
|
||||
logger.info("Cleanup scheduler stopped")
|
||||
except Exception as e:
|
||||
logger.warning(f"Error stopping cleanup scheduler: {e}")
|
||||
|
||||
# Connection draining - wait for active requests to complete
|
||||
await drain_connections(timeout=30.0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user