fix: not shutting down during scan
Local Docker Build (Dev) / build-dev (push) Successful in 4s
Local Docker Build (Main) / build (pull_request) Successful in 4s
Local Docker Build (Main) / deploy (pull_request) Has been skipped

This commit is contained in:
2025-10-20 10:36:23 -04:00
parent 808322c7c7
commit 748392c425
3 changed files with 94 additions and 2 deletions
+31 -1
View File
@@ -682,7 +682,8 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
try:
# Determine force_scan based on scan mode
force_scan = (scan_mode == "full")
result = movie_processor.process_movie(item, webhook_mode=False, force_scan=force_scan)
shutdown_event = dependencies.get("shutdown_event")
result = movie_processor.process_movie(item, webhook_mode=False, force_scan=force_scan, shutdown_event=shutdown_event)
movie_total += 1
if result == "skipped":
movie_skipped += 1
@@ -691,6 +692,9 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
elif result == "no_video_files":
print(f"INFO: Skipped empty directory: {item.name}")
movie_skipped += 1
elif result == "shutdown":
print("INFO: ⚠️ SHUTDOWN SIGNAL RECEIVED - Stopping movie scan gracefully")
return
except Exception as e:
print(f"ERROR: Failed processing movie {item}: {e}")
movie_total += 1
@@ -1207,6 +1211,28 @@ async def cleanup_orphaned_movies(dependencies: dict):
}
async def cleanup_orphaned_series(dependencies: dict):
"""Find and delete TV series that don't have corresponding directories"""
db = dependencies["db"]
try:
deleted_series = db.delete_orphaned_series()
return {
"success": True,
"message": f"Cleaned up {len(deleted_series)} orphaned TV series",
"deleted_count": len(deleted_series),
"deleted_series": deleted_series
}
except Exception as e:
return {
"success": False,
"error": str(e),
"message": "Failed to cleanup orphaned TV series"
}
# ---------------------------
# Route Registration
# ---------------------------
@@ -1277,6 +1303,10 @@ def register_routes(app, dependencies: dict):
async def _cleanup_orphaned_movies():
return await cleanup_orphaned_movies(dependencies)
@app.post("/database/cleanup/orphaned-series")
async def _cleanup_orphaned_series():
return await cleanup_orphaned_series(dependencies)
@app.post("/manual/scan")
async def _manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = None, scan_type: str = "both", scan_mode: str = "smart"):
return await manual_scan(background_tasks, path, scan_type, scan_mode, dependencies)