Detect the app is exiting and avoid reconnecting to computes.

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

View File

@ -21,7 +21,6 @@ import asyncio
import async_timeout
import socket
import json
import uuid
import sys
import io
from operator import itemgetter
@ -295,6 +294,7 @@ class Compute:
"""
:param topology_dump: Filter to keep only properties require for saving on disk
"""
if topology_dump:
return {
"compute_id": self._id,
@ -486,7 +486,8 @@ class Compute:
log.info(f"Connection closed to compute '{self._id}' WebSocket '{ws_url}'")
# Try to reconnect after 1 second if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
if self.id != "local" and not hasattr(sys, "_called_from_test") or not sys._called_from_test:
from gns3server.api.server import app
if not app.state.exiting and not hasattr(sys, "_called_from_test") or not sys._called_from_test:
log.info(f"Reconnecting to to compute '{self._id}' WebSocket '{ws_url}'")
asyncio.get_event_loop().call_later(1, lambda: asyncio.ensure_future(self.connect()))