|
@@ -296,6 +296,20 @@ async def test(request: Request):
|
|
|
request_origin = request.headers.get('origin')
|
|
|
if request_origin is None:
|
|
|
request_origin = "unknown"
|
|
|
- content = {"message": "Hello World" + request_origin}
|
|
|
+ content = {"message": "Hello World" + request_origin, "db": "disconnect"}
|
|
|
headers = {'Access-Control-Allow-Origin': request_origin}
|
|
|
+ try:
|
|
|
+ database.connect(reuse_if_open=True)
|
|
|
+ dt = CustomUser.select()
|
|
|
+ for item in dt:
|
|
|
+ print(item.id)
|
|
|
+ content["db"] = "connected"
|
|
|
+ except OperationalError as e:
|
|
|
+ if 'MySQL server has gone away' in str(e):
|
|
|
+ content["db"] = "broke"
|
|
|
+ database.close()
|
|
|
+ database.connect()
|
|
|
+ if database.is_connected():
|
|
|
+ content["db"] = "broke , reconnect"
|
|
|
+ logging.info("reconnect database")
|
|
|
return JSONResponse(content=content, headers=headers)
|