add http test | fix ctrl+c shutdown

This commit is contained in:
mario
2025-07-11 15:48:34 +07:00
parent 853cc70edb
commit 0cdd52db94
6 changed files with 138 additions and 139 deletions

View File

@@ -17,7 +17,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from process import process_study_by_accession
from utils.logger import setup_logger
from utils.dicom_utils import create_directory_if_not_exists
from utils.cleanup import register_exit_handlers
from api_cleanup import register_api_cleanup
# Create API logger
api_logger = setup_logger("api", "logs/api.log")
@@ -71,10 +71,23 @@ def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
@app.on_event("startup")
async def startup_event():
"""Initialize resources when the API starts."""
register_exit_handlers()
# Create necessary directories
create_directory_if_not_exists("logs")
# Use our custom API cleanup registration that avoids signal handlers
register_api_cleanup()
api_logger.info("API started successfully")
@app.on_event("shutdown")
async def shutdown_event():
"""Clean up resources when the API shuts down."""
api_logger.info("API shutting down, cleaning up resources...")
# Perform cleanup operations here
from utils.cleanup import cleanup_dicom_files
cleanup_dicom_files()
api_logger.info("Cleanup complete, API shutdown successful")
@app.get("/", response_model=MigrationResponse)
async def root():
"""