add http test | fix ctrl+c shutdown
This commit is contained in:
@@ -4,6 +4,7 @@ Script to run the FastAPI server for DICOM migration service.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
import uvicorn
|
||||
import argparse
|
||||
|
||||
@@ -16,6 +17,12 @@ def parse_args():
|
||||
parser.add_argument('--reload', action='store_true', help='Enable auto-reload for development')
|
||||
return parser.parse_args()
|
||||
|
||||
def handle_exit(signum, frame):
|
||||
"""Handle exit signals gracefully."""
|
||||
print(f"Received signal {signum}, shutting down gracefully...")
|
||||
# Let uvicorn handle the exit
|
||||
sys.exit(0)
|
||||
|
||||
def main():
|
||||
"""Main function to run the API server."""
|
||||
args = parse_args()
|
||||
@@ -29,6 +36,10 @@ def main():
|
||||
print("WARNING: API_TOKEN not set. Using default token 'token-his2-untuk-hit-api-migrasi-clarity'.")
|
||||
print("Set environment variable API_TOKEN or use --token argument for better security.")
|
||||
|
||||
# Set up signal handlers for graceful shutdown
|
||||
signal.signal(signal.SIGINT, handle_exit)
|
||||
signal.signal(signal.SIGTERM, handle_exit)
|
||||
|
||||
print(f"Starting DICOM Migration API server on {args.host}:{args.port}")
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
|
||||
Reference in New Issue
Block a user