feat: implement graceful shutdown with SIGINT/SIGTERM support
- Add WebSocket shutdown() with client notification and graceful close - Enhance download service stop() with pending state persistence - Expand FastAPI lifespan shutdown with proper cleanup sequence - Add SQLite WAL checkpoint before database close - Update stop_server.sh to use SIGTERM with timeout fallback - Configure uvicorn timeout_graceful_shutdown=30s - Update ARCHITECTURE.md with shutdown documentation
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
"""
|
||||
Startup script for the Aniworld FastAPI application.
|
||||
|
||||
This script starts the application with proper logging configuration.
|
||||
This script starts the application with proper logging configuration
|
||||
and graceful shutdown support via Ctrl+C (SIGINT) or SIGTERM.
|
||||
"""
|
||||
import uvicorn
|
||||
|
||||
@@ -15,6 +16,11 @@ if __name__ == "__main__":
|
||||
# Run the application with logging.
|
||||
# Only watch .py files in src/, explicitly exclude __pycache__.
|
||||
# This prevents reload loops from .pyc compilation.
|
||||
#
|
||||
# Graceful shutdown:
|
||||
# - Ctrl+C (SIGINT) or SIGTERM triggers graceful shutdown
|
||||
# - timeout_graceful_shutdown ensures shutdown completes within 30s
|
||||
# - The FastAPI lifespan handler orchestrates cleanup in proper order
|
||||
uvicorn.run(
|
||||
"src.server.fastapi_app:app",
|
||||
host="127.0.0.1",
|
||||
@@ -24,4 +30,5 @@ if __name__ == "__main__":
|
||||
reload_includes=["*.py"],
|
||||
reload_excludes=["*/__pycache__/*", "*.pyc"],
|
||||
log_config=log_config,
|
||||
timeout_graceful_shutdown=30, # Allow 30s for graceful shutdown
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user