ro_cleanup_delay

This commit is contained in:
Maxim Devaev 2022-06-19 04:10:42 +03:00
parent 74e81b6e03
commit 805ff9dd5f
3 changed files with 9 additions and 3 deletions

View File

@ -497,6 +497,7 @@ def _get_config_scheme() -> Dict:
"storage": Option("/var/lib/kvmd/pst", type=valid_abs_dir, unpack_as="storage_path"),
"ro_retries_delay": Option(10.0, type=valid_float_f01),
"ro_cleanup_delay": Option(3.0, type=valid_float_f01),
"remount_cmd": Option([
"/usr/bin/sudo", "--non-interactive",

View File

@ -46,6 +46,7 @@ class PstServer(HttpServer): # pylint: disable=too-many-arguments,too-many-inst
self,
storage_path: str,
ro_retries_delay: float,
ro_cleanup_delay: float,
remount_cmd: List[str],
) -> None:
@ -53,6 +54,7 @@ class PstServer(HttpServer): # pylint: disable=too-many-arguments,too-many-inst
self.__data_path = os.path.join(storage_path, "data")
self.__ro_retries_delay = ro_retries_delay
self.__ro_cleanup_delay = ro_cleanup_delay
self.__remount_cmd = remount_cmd
self.__notifier = aiotools.AioNotifier()
@ -83,7 +85,8 @@ class PstServer(HttpServer): # pylint: disable=too-many-arguments,too-many-inst
await aiotools.stop_all_deadly_tasks()
logger.info("Disconnecting clients ...")
await self.__broadcast_storage_state(False)
await self._close_all_wss()
if (await self._close_all_wss()):
await asyncio.sleep(self.__ro_cleanup_delay)
logger.info("On-Shutdown complete")
async def _on_cleanup(self) -> None:

View File

@ -359,9 +359,11 @@ class HttpServer:
)
], return_exceptions=True)
async def _close_all_wss(self) -> None:
for ws in self._get_wss():
async def _close_all_wss(self) -> bool:
wss = self._get_wss()
for ws in wss:
await self.__close_ws(ws)
return bool(wss)
def _get_wss(self) -> List[WsSession]:
return list(self.__ws_sessions)