INNER CODE UNIT · Python
shutdown_event
AleksNeStu/ai-real-estate-assistant · apps/api/api/main.py:392
async def shutdown_event():
"""
Clean up resources on shutdown with graceful drain period.
This handler:
1. Logs the shutdown initiation
2. Waits for a drain period to allow in-flight requests to complete
3. Stops background services (scheduler, monitors)
4. Closes database/vector store connections
5. Logs completion of shutdown
"""
logger.info("Graceful shutdown initiated...")
shutdown_start_time = asyncio.get_event_loop().time()
# Step 1: Stop accepting new requests (handled by uvicorn)
# We just need to drain in-flight requests during this period
# Step 2: Stop Uptime Monitor first (doesn't depend on other services)