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:
egg
2025-12-14 12:41:01 +08:00
parent 81a0a3ab0f
commit 73112db055
23 changed files with 1359 additions and 634 deletions

View File

@@ -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)