Detect the app is exiting and avoid reconnecting to computes.

This commit is contained in:
grossmj committed 2021-04-17 18:33:20 +09:30
1 parent 6b8ce8219c
commit bad3ef7003
4 files changed
+19 -13

No files matched your search

+13 -1
View File
@@ -25,7 +25,7 @@ from fastapi import FastAPI, Request
from starlette.exceptions import HTTPException as StarletteHTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from uvicorn.main import Server as UvicornServer
from gns3server.controller.controller_error import (
ControllerError,
@@ -82,6 +82,18 @@ def get_application() -> FastAPI:
app = get_application()
# Monkey Patch uvicorn signal handler to detect the application is shutting down
app.state.exiting = False
unicorn_exit_handler = UvicornServer.handle_exit
def handle_exit(*args, **kwargs):
app.state.exiting = True
unicorn_exit_handler(*args, **kwargs)
UvicornServer.handle_exit = handle_exit
@app.exception_handler(ControllerError)
async def controller_error_handler(request: Request, exc: ControllerError):