1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-14 13:29:25 +08:00

Merge branch 'master_lme'

# Conflicts:
#	alas.py
This commit is contained in:
Zuosizhu
2023-04-20 01:19:40 +08:00
30 changed files with 457 additions and 126 deletions

37
alas.py
View File

@@ -22,6 +22,11 @@ class AzurLaneAutoScript:
def __init__(self, config_name='alas'):
logger.hr('Start', level=0)
self.config_name = config_name
# Skip first restart
self.is_first_task = True
# Failure count of tasks
# Key: str, task name, value: int, failure count
self.failure_record = {}
@cached_property
def config(self):
@@ -441,6 +446,7 @@ class AzurLaneAutoScript:
if task.next_run > datetime.now():
logger.info(f'Wait until {task.next_run} for task `{task.command}`')
self.is_first_task = False
method = self.config.Optimization_WhenTaskQueueEmpty
if method == 'close_game':
logger.info('Close game during wait')
@@ -448,7 +454,7 @@ class AzurLaneAutoScript:
release_resources()
self.device.release_during_wait()
if not self.wait_until(task.next_run):
del self.__dict__['config']
del_cached_property(self, 'config')
continue
self.run('start')
elif method == 'goto_main':
@@ -457,21 +463,21 @@ class AzurLaneAutoScript:
release_resources()
self.device.release_during_wait()
if not self.wait_until(task.next_run):
del self.__dict__['config']
del_cached_property(self, 'config')
continue
elif method == 'stay_there':
logger.info('Stay there during wait')
release_resources()
self.device.release_during_wait()
if not self.wait_until(task.next_run):
del self.__dict__['config']
del_cached_property(self, 'config')
continue
else:
logger.warning(f'Invalid Optimization_WhenTaskQueueEmpty: {method}, fallback to stay_there')
release_resources()
self.device.release_during_wait()
if not self.wait_until(task.next_run):
del self.__dict__['config']
del_cached_property(self, 'config')
continue
break
@@ -481,12 +487,10 @@ class AzurLaneAutoScript:
def loop(self):
logger.set_file_logger(self.config_name)
logger.info(f'Start scheduler loop: {self.config_name}')
is_first = True
# Try forced task_call restart to reset GG status
self.checker.wait_until_available()
GGHandler(config=self.config, device=self.device).handle_restart_before_tasks()
failure_record = {}
check_fail=0
check_fail = 0
while 1:
# Check update event from GUI
if self.stop_event is not None:
@@ -511,13 +515,13 @@ class AzurLaneAutoScript:
# Skip first restart
if task == 'Restart':
if is_first:
if self.is_first_task:
logger.info('Skip task `Restart` at scheduler start')
else:
from module.handler.login import LoginHandler
LoginHandler(self.config, self.device).app_restart()
self.config.task_delay(server_update=True)
del self.__dict__['config']
del_cached_property(self, 'config')
continue
# Check GG config before a task begins (to reset temporary config), and decide to enable it.
@@ -526,9 +530,9 @@ class AzurLaneAutoScript:
GGHandler(config=self.config, device=self.device).check_then_set_gg_status(inflection.underscore(task))
check_fail = 0
except GameStuckError:
del self.__dict__['config']
del_cached_property(self, 'config')
check_fail += 1
if check_fail <=3:
if check_fail <= 3:
continue
else:
handle_notify(self.config.Error_OnePushConfig,
@@ -539,7 +543,6 @@ class AzurLaneAutoScript:
)
exit(1)
# Run
logger.info(f'Scheduler: Start task `{task}`')
self.device.stuck_record_clear()
@@ -547,12 +550,12 @@ class AzurLaneAutoScript:
logger.hr(task, level=0)
success = self.run(inflection.underscore(task))
logger.info(f'Scheduler: End task `{task}`')
is_first = False
self.is_first_task = False
# Check failures
failed = deep_get(failure_record, keys=task, default=0)
failed = deep_get(self.failure_record, keys=task, default=0)
failed = 0 if success else failed + 1
deep_set(failure_record, keys=task, value=failed)
deep_set(self.failure_record, keys=task, value=failed)
if failed >= 3:
logger.critical(f"Task `{task}` failed 3 or more times.")
logger.critical("Possible reason #1: You haven't used it correctly. "
@@ -569,11 +572,11 @@ class AzurLaneAutoScript:
exit(1)
if success:
del self.__dict__['config']
del_cached_property(self, 'config')
continue
elif self.config.Error_HandleError:
# self.config.task_delay(success=False)
del self.__dict__['config']
del_cached_property(self, 'config')
self.checker.check_now()
continue
else: