From 0f49d925a8dfca004abcbef50432ff75ea37ec5b Mon Sep 17 00:00:00 2001 From: LA-DI-DA <11174151+0O0o0oOoO00@users.noreply.github.com> Date: Mon, 20 Nov 2023 22:40:22 +0800 Subject: [PATCH] Fix: incorrect place of exit when server is under maintenance --- alas.py | 14 ++------------ module/server_checker.py | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/alas.py b/alas.py index 300c7151f..b553e0238 100644 --- a/alas.py +++ b/alas.py @@ -65,7 +65,7 @@ class AzurLaneAutoScript: def checker(self): try: from module.server_checker import ServerChecker - checker = ServerChecker(server=self.config.Emulator_ServerName) + checker = ServerChecker(server=self.config.Emulator_ServerName, config=self.config) return checker except Exception as e: logger.exception(e) @@ -160,17 +160,7 @@ class AzurLaneAutoScript: LoginHandler(self.config, self.device).app_restart() return False else: - if deep_get(self.config.data, "Restart.ExitWhenMaintenance.Enable"): - if deep_get(self.config.data, "Restart.ExitWhenMaintenance.Notify"): - handle_notify( - self.config.Error_OnePushConfig, - title=f"Alas <{self.config_name}> exit", - content=f"Server is under maintenance, <{self.config_name}> exits" - ) - logger.info("Server is under maintenance, exit") - exit(0) - else: - self.checker.wait_until_available() + self.checker.wait_until_available() return False except ScriptError as e: logger.critical(e) diff --git a/module/server_checker.py b/module/server_checker.py index 93bae2184..1f6b14a5e 100644 --- a/module/server_checker.py +++ b/module/server_checker.py @@ -4,13 +4,17 @@ from json import JSONDecodeError import requests from module.base.timer import Timer +from module.config.config import AzurLaneConfig from module.config.server import VALID_SERVER_LIST as server_list +from module.config.utils import deep_get from module.exception import ScriptError from module.logger import logger +from module.notify import handle_notify class ServerChecker: - def __init__(self, server: str) -> None: + def __init__(self, server: str, config: AzurLaneConfig) -> None: + self.config = config self._base: str = 'http://sc.shiratama.cn' self._api: dict = { 'get_state': '/server/get_state', # post @@ -114,9 +118,19 @@ class ServerChecker: if not self._state[0]: self._recover = True else: - if self._timer.limit < 600: - self._timer.limit += 120 - logger.info(f'Server checker will retry after {self._timer.limit}s') + if deep_get(self.config.data, "Restart.ExitWhenMaintenance.Enable"): + if deep_get(self.config.data, "Restart.ExitWhenMaintenance.Notify"): + handle_notify( + self.config.Error_OnePushConfig, + title=f"Alas <{self.config.config_name}> exit", + content=f"Server is under maintenance, exit" + ) + logger.info("Server is under maintenance, exit") + exit(0) + else: + if self._timer.limit < 600: + self._timer.limit += 120 + logger.info(f'Server checker will retry after {self._timer.limit}s') self._timer.reset() except ScriptError as e: logger.warning(str(e))