1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-21 04:09:30 +08:00

Fix: incorrect place of exit when server is under maintenance

This commit is contained in:
LA-DI-DA
2023-11-20 22:40:22 +08:00
parent c262bbd4af
commit 0f49d925a8
2 changed files with 20 additions and 16 deletions

14
alas.py
View File

@@ -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)

View File

@@ -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))