mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 14:29:26 +08:00
ref: use a wrap class to control scheduler watcher
This commit is contained in:
15
alas.py
15
alas.py
@@ -604,8 +604,6 @@ 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
|
||||
@@ -835,7 +833,7 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
||||
release_resources(next_task=task.command)
|
||||
|
||||
if task.next_run > datetime.now():
|
||||
self.scheduler_watcher.no_task()
|
||||
self.config.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
|
||||
@@ -882,15 +880,6 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
||||
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
|
||||
|
||||
if self.is_azur and self.config.full_config.Hook_HookGeneral_Enable and self.config.full_config.Hook_HookGeneral_RestartEveryTime:
|
||||
logger.info("Hook enabled, do restart")
|
||||
self.restart()
|
||||
@@ -931,7 +920,7 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
||||
logger.info(f'Scheduler: Start task `{task}`')
|
||||
|
||||
if self.is_azur:
|
||||
self.scheduler_watcher.switch_task(task)
|
||||
self.config.scheduler_watcher.switch_task(task)
|
||||
luahook_disable_all(self.config, self.device)
|
||||
luahook_crack_all(self.config, self.device)
|
||||
|
||||
|
||||
@@ -179,9 +179,6 @@ class CampaignBase(CampaignUI, Map, AutoSearchCombat):
|
||||
self.battle_count += 1
|
||||
|
||||
|
||||
from module.scheduler_watcher import request_extend_task_deadline
|
||||
|
||||
|
||||
class CampaignBase(CampaignBase):
|
||||
def run(self):
|
||||
logger.hr(self.ENTRANCE, level=2)
|
||||
@@ -202,7 +199,7 @@ class CampaignBase(CampaignBase):
|
||||
self.lv_get()
|
||||
|
||||
# Run
|
||||
request_extend_task_deadline()
|
||||
self.config.scheduler_watcher.request_extend_task_deadline()
|
||||
for _ in range(20):
|
||||
try:
|
||||
if not self.map_is_auto_search:
|
||||
|
||||
@@ -793,12 +793,17 @@ class MultiSetWrapper:
|
||||
|
||||
|
||||
from module.config.full_config import AzurLaneFullConfig
|
||||
from module.scheduler_watcher import AzurLaneSchedulerWatcher
|
||||
|
||||
|
||||
class AzurLaneConfig(AzurLaneConfig):
|
||||
def __init__(self, config_name, task=None):
|
||||
super().__init__(config_name, task)
|
||||
|
||||
@property
|
||||
def scheduler_watcher(self):
|
||||
return AzurLaneSchedulerWatcher(self)
|
||||
|
||||
@property
|
||||
def full_config(self):
|
||||
return AzurLaneFullConfig(self)
|
||||
|
||||
@@ -250,9 +250,6 @@ class Exercise(ExerciseCombat):
|
||||
self.config.task_delay(success=False)
|
||||
|
||||
|
||||
from module.scheduler_watcher import request_extend_task_deadline
|
||||
|
||||
|
||||
class Exercise(Exercise):
|
||||
def run(self):
|
||||
self.ui_ensure(page_exercise)
|
||||
@@ -288,7 +285,7 @@ class Exercise(Exercise):
|
||||
break
|
||||
|
||||
logger.hr(f'Exercise remain {self.remain}', level=1)
|
||||
request_extend_task_deadline()
|
||||
self.config.scheduler_watcher.request_extend_task_deadline()
|
||||
if self.config.Exercise_OpponentChooseMode == "easiest_else_exp":
|
||||
success = self._exercise_easiest_else_exp()
|
||||
else:
|
||||
|
||||
@@ -950,9 +950,6 @@ class OSMap(OSFleet, Map, GlobeCamera, StrategicSearchHandler):
|
||||
return False
|
||||
|
||||
|
||||
from module.scheduler_watcher import request_extend_task_deadline
|
||||
|
||||
|
||||
class OSMap(OSMap):
|
||||
def os_auto_search_daemon(self, drop=None, strategic=False, skip_first_screenshot=True):
|
||||
logger.hr('OS auto search', level=2)
|
||||
@@ -1010,7 +1007,7 @@ class OSMap(OSMap):
|
||||
self.on_auto_search_battle_count_add()
|
||||
if strategic and self.config.task_switched():
|
||||
self.interrupt_auto_search()
|
||||
request_extend_task_deadline()
|
||||
self.config.scheduler_watcher.request_extend_task_deadline()
|
||||
result = self.auto_search_combat(drop=drop)
|
||||
if result:
|
||||
finished_combat += 1
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
from module.config.full_config import AzurLaneFullConfig
|
||||
from module.counter import MaxCounter, CounterReachMaxCountException
|
||||
from module.logger import logger
|
||||
from module.notify import handle_notify
|
||||
@@ -21,9 +22,8 @@ class SchedulerWatcher:
|
||||
self.current_task = None
|
||||
self.min_timedelta = None
|
||||
|
||||
def set_alas_obj(self, alas_obj):
|
||||
self.alas_obj = alas_obj
|
||||
self.config = alas_obj.config
|
||||
def set_alas_config(self, config):
|
||||
self.config = config
|
||||
|
||||
def start_watch(self, min_timedelta, max_warning_count):
|
||||
if self.watcher is not None:
|
||||
@@ -85,6 +85,11 @@ class SchedulerWatcher:
|
||||
)
|
||||
os._exit(-1)
|
||||
|
||||
def is_alive(self):
|
||||
if self.watcher is None:
|
||||
return False
|
||||
return self.watcher.is_alive()
|
||||
|
||||
@staticmethod
|
||||
def get_instance() -> "SchedulerWatcher":
|
||||
if SchedulerWatcher.instance is None:
|
||||
@@ -92,11 +97,28 @@ class SchedulerWatcher:
|
||||
return SchedulerWatcher.instance
|
||||
|
||||
|
||||
def request_extend_task_deadline():
|
||||
ins = SchedulerWatcher.get_instance()
|
||||
ins.request_extend_task_deadline()
|
||||
class AzurLaneSchedulerWatcher:
|
||||
def __init__(self, config):
|
||||
full_config: AzurLaneFullConfig = config.full_config
|
||||
if full_config.Restart_SchedulerWatcher_Enable:
|
||||
self.watcher: SchedulerWatcher = SchedulerWatcher.get_instance()
|
||||
if not self.watcher.is_alive():
|
||||
self.watcher.set_alas_config(config)
|
||||
self.watcher.start_watch(
|
||||
min_timedelta=full_config.Restart_SchedulerWatcher_TimeDelta,
|
||||
max_warning_count=full_config.Restart_SchedulerWatcher_WarningCount
|
||||
)
|
||||
else:
|
||||
self.watcher = None
|
||||
|
||||
def request_extend_task_deadline(self):
|
||||
if self.watcher is not None:
|
||||
self.watcher.request_extend_task_deadline()
|
||||
|
||||
def no_task():
|
||||
ins = SchedulerWatcher.get_instance()
|
||||
ins.no_task()
|
||||
def switch_task(self, task):
|
||||
if self.watcher is not None:
|
||||
self.watcher.switch_task(task)
|
||||
|
||||
def no_task(self):
|
||||
if self.watcher is not None:
|
||||
self.watcher.no_task()
|
||||
|
||||
Reference in New Issue
Block a user