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

add: add scheduler watcher support

This commit is contained in:
0O0o0oOoO00
2025-09-12 22:35:00 +08:00
parent 1918e56dbb
commit 998cf9c65f
15 changed files with 454 additions and 0 deletions

67
alas.py
View File

@@ -587,6 +587,7 @@ class AzurLaneAutoScript:
from module.luahook.crack import *
from module.scheduler_watcher import *
class AzurLaneAutoScript(AzurLaneAutoScript):
@@ -602,6 +603,8 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
elif self.class_name == "ArknightsAutoScript":
self.is_ark = True
self.scheduler_watcher = None
full_config = self.config.full_config
self.is_fatal_error_restart = full_config.Restart_GameRestart_FatalErrorRestart
self.max_retry_times_for_same_task_failed = full_config.Restart_GameRestart_MaxRetryTimesForSameTaskFailed
@@ -823,10 +826,73 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
def coalition_sp(self):
super().coalition_sp()
def get_next_task(self):
while 1:
task = self.config.get_next()
self.config.task = task
self.config.bind(task)
from module.base.resource import release_resources
if self.config.task.command != 'Alas':
release_resources(next_task=task.command)
if task.next_run > datetime.now():
self.scheduler_watcher.no_task()
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')
self.device.app_stop()
release_resources()
self.device.release_during_wait()
if not self.wait_until(task.next_run):
del_cached_property(self, 'config')
continue
if task.command != 'Restart':
self.config.task_call('Restart')
del_cached_property(self, 'config')
continue
elif method == 'goto_main':
logger.info('Goto main page during wait')
self.run('goto_main')
release_resources()
self.device.release_during_wait()
if not self.wait_until(task.next_run):
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_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_cached_property(self, 'config')
continue
break
AzurLaneConfig.is_hoarding_task = False
return task.command
def loop(self):
if self.is_azur:
CrackResource(self.config, self.device).ensure()
if self.is_azur and self.config.full_config.Restart_SchedulerWatcher_Enable:
watcher = SchedulerWatcher.get_instance()
watcher.set_alas_obj(self)
watcher.start_watch(
min_timedelta=self.config.full_config.Restart_SchedulerWatcher_TimeDelta,
max_warning_count=self.config.full_config.Restart_SchedulerWatcher_WarningCount
)
self.scheduler_watcher = watcher
logger.set_file_logger(self.config_name)
logger.info(f'Start scheduler loop: {self.config_name}')
@@ -861,6 +927,7 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
# Run
logger.info(f'Scheduler: Start task `{task}`')
self.scheduler_watcher.switch_task(task)
self.device.stuck_record_clear()
self.device.click_record_clear()
logger.hr(task, level=0)