From ae1e32aef2a11667482c55537aeaee794a7dd5f1 Mon Sep 17 00:00:00 2001 From: 0O0o0oOoO00 <11174151+0O0o0oOoO00@users.noreply.github.com> Date: Sat, 9 Aug 2025 20:08:57 +0800 Subject: [PATCH] adj: separate the settings of the scheduler watcher --- alas.py | 7 +++++-- config/template.json | 6 +++++- module/config/argument/args.json | 14 ++++++++++++-- module/config/argument/argument.yaml | 5 ++++- module/config/argument/task.yaml | 1 + module/config/config_generated.py | 6 +++++- module/config/i18n/en-US.json | 22 ++++++++++++++++++---- module/config/i18n/ja-JP.json | 22 ++++++++++++++++++---- module/config/i18n/zh-CN.json | 22 ++++++++++++++++++---- module/config/i18n/zh-TW.json | 22 ++++++++++++++++++---- scheduler_watcher.py | 15 +++++++++------ 11 files changed, 113 insertions(+), 29 deletions(-) diff --git a/alas.py b/alas.py index 31407b4dc..5cab4ce9a 100644 --- a/alas.py +++ b/alas.py @@ -796,8 +796,11 @@ class AzurLaneAutoScript: exit(0) def loop(self): - if deep_get(self.config.data, "Restart.InstanceRestart.EnableSchedulerWatcher", False): - self.scheduler_watcher.start_watch() + if deep_get(self.config.data, "Restart.SchedulerWatcher.Enable", False): + self.scheduler_watcher.start_watch( + min_timedelta=deep_get(self.config.data, "Restart.SchedulerWatcher.TimeDelta", 10), + max_warning_count=deep_get(self.config.data, "Restart.SchedulerWatcher.WarningCount", 3) + ) if self.is_azur: CrackResource(self.config, self.device).ensure() diff --git a/config/template.json b/config/template.json index 39842b68f..43d5d1d82 100644 --- a/config/template.json +++ b/config/template.json @@ -190,8 +190,12 @@ "AttemptsToRestart": 114514, "NotifyWhenAutoRestart": false }, + "SchedulerWatcher": { + "Enable": false, + "TimeDelta": 10, + "WarningCount": 3 + }, "InstanceRestart": { - "EnableSchedulerWatcher": false, "Enabled": false, "AttemptsToRestart": 114514, "NotifyWhenAutoRestart": false, diff --git a/module/config/argument/args.json b/module/config/argument/args.json index 7b051622d..d57017b85 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -815,11 +815,21 @@ "value": false } }, - "InstanceRestart": { - "EnableSchedulerWatcher": { + "SchedulerWatcher": { + "Enable": { "type": "checkbox", "value": false }, + "TimeDelta": { + "type": "input", + "value": 10 + }, + "WarningCount": { + "type": "input", + "value": 3 + } + }, + "InstanceRestart": { "Enabled": { "type": "checkbox", "value": false diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index e760b020e..3da12bed1 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -1285,8 +1285,11 @@ AutoRestart: NotifyWhenAutoRestart: type: checkbox value: false +SchedulerWatcher: + Enable: false + TimeDelta: 10 + WarningCount: 3 InstanceRestart: - EnableSchedulerWatcher: false Enabled: type: checkbox value: false diff --git a/module/config/argument/task.yaml b/module/config/argument/task.yaml index 362331218..a3689919a 100644 --- a/module/config/argument/task.yaml +++ b/module/config/argument/task.yaml @@ -26,6 +26,7 @@ Alas: Restart: - Scheduler - AutoRestart + - SchedulerWatcher - InstanceRestart - ExitWhenMaintenance OthersLogin: diff --git a/module/config/config_generated.py b/module/config/config_generated.py index 68015bb16..b47126cbc 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -774,8 +774,12 @@ class GeneratedConfig: AutoRestart_AttemptsToRestart = 114514 AutoRestart_NotifyWhenAutoRestart = False + # Group `SchedulerWatcher` + SchedulerWatcher_Enable = False + SchedulerWatcher_TimeDelta = 10 + SchedulerWatcher_WarningCount = 3 + # Group `InstanceRestart` - InstanceRestart_EnableSchedulerWatcher = False InstanceRestart_Enabled = False InstanceRestart_AttemptsToRestart = 114514 InstanceRestart_NotifyWhenAutoRestart = False diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 2a977f494..96a9dcd30 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -4240,15 +4240,29 @@ "help": "AutoRestart.NotifyWhenAutoRestart.help" } }, + "SchedulerWatcher": { + "_info": { + "name": "SchedulerWatcher._info.name", + "help": "SchedulerWatcher._info.help" + }, + "Enable": { + "name": "SchedulerWatcher.Enable.name", + "help": "SchedulerWatcher.Enable.help" + }, + "TimeDelta": { + "name": "SchedulerWatcher.TimeDelta.name", + "help": "SchedulerWatcher.TimeDelta.help" + }, + "WarningCount": { + "name": "SchedulerWatcher.WarningCount.name", + "help": "SchedulerWatcher.WarningCount.help" + } + }, "InstanceRestart": { "_info": { "name": "InstanceRestart._info.name", "help": "InstanceRestart._info.help" }, - "EnableSchedulerWatcher": { - "name": "InstanceRestart.EnableSchedulerWatcher.name", - "help": "InstanceRestart.EnableSchedulerWatcher.help" - }, "Enabled": { "name": "InstanceRestart.Enabled.name", "help": "InstanceRestart.Enabled.help" diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index 58112fae4..670f7d57c 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -4240,15 +4240,29 @@ "help": "AutoRestart.NotifyWhenAutoRestart.help" } }, + "SchedulerWatcher": { + "_info": { + "name": "SchedulerWatcher._info.name", + "help": "SchedulerWatcher._info.help" + }, + "Enable": { + "name": "SchedulerWatcher.Enable.name", + "help": "SchedulerWatcher.Enable.help" + }, + "TimeDelta": { + "name": "SchedulerWatcher.TimeDelta.name", + "help": "SchedulerWatcher.TimeDelta.help" + }, + "WarningCount": { + "name": "SchedulerWatcher.WarningCount.name", + "help": "SchedulerWatcher.WarningCount.help" + } + }, "InstanceRestart": { "_info": { "name": "InstanceRestart._info.name", "help": "InstanceRestart._info.help" }, - "EnableSchedulerWatcher": { - "name": "InstanceRestart.EnableSchedulerWatcher.name", - "help": "InstanceRestart.EnableSchedulerWatcher.help" - }, "Enabled": { "name": "InstanceRestart.Enabled.name", "help": "InstanceRestart.Enabled.help" diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index ee8e8c748..b6400b093 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -4240,15 +4240,29 @@ "help": "因出错而自动重启时通知,不建议开启,因为可能会很烦" } }, + "SchedulerWatcher": { + "_info": { + "name": "调度器监视器", + "help": "如果要开启此功能则建议开启自动实例重启\n注意: 修改以下的配置后要重新启动Alas实例" + }, + "Enable": { + "name": "启用", + "help": "" + }, + "TimeDelta": { + "name": "单次时限(分钟)", + "help": "" + }, + "WarningCount": { + "name": "最大警告次数", + "help": "" + } + }, "InstanceRestart": { "_info": { "name": "重启Alas实例", "help": "" }, - "EnableSchedulerWatcher": { - "name": "调度器监视器", - "help": "如果要开启此功能则建议开启自动实例重启\n注意: 此选项修改后要重新启动Alas" - }, "Enabled": { "name": "启用", "help": "" diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index 63fc390ba..d7ddd38f2 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -4240,15 +4240,29 @@ "help": "AutoRestart.NotifyWhenAutoRestart.help" } }, + "SchedulerWatcher": { + "_info": { + "name": "SchedulerWatcher._info.name", + "help": "SchedulerWatcher._info.help" + }, + "Enable": { + "name": "SchedulerWatcher.Enable.name", + "help": "SchedulerWatcher.Enable.help" + }, + "TimeDelta": { + "name": "SchedulerWatcher.TimeDelta.name", + "help": "SchedulerWatcher.TimeDelta.help" + }, + "WarningCount": { + "name": "SchedulerWatcher.WarningCount.name", + "help": "SchedulerWatcher.WarningCount.help" + } + }, "InstanceRestart": { "_info": { "name": "InstanceRestart._info.name", "help": "InstanceRestart._info.help" }, - "EnableSchedulerWatcher": { - "name": "InstanceRestart.EnableSchedulerWatcher.name", - "help": "InstanceRestart.EnableSchedulerWatcher.help" - }, "Enabled": { "name": "InstanceRestart.Enabled.name", "help": "InstanceRestart.Enabled.help" diff --git a/scheduler_watcher.py b/scheduler_watcher.py index 8ca4eae93..4d5309a5b 100644 --- a/scheduler_watcher.py +++ b/scheduler_watcher.py @@ -31,17 +31,20 @@ class SchedulerWatcher: def __init__(self): self.alas_obj = None self.watcher: threading.Thread = None - self.warning_count = Counter(3) + self.warning_count = None self.warning_time = None self.current_task = None + self.min_timedelta = None def set_alas_obj(self, alas_obj): self.alas_obj = alas_obj - def start_watch(self): + def start_watch(self, min_timedelta, max_warning_count): if self.watcher is not None: if self.watcher.is_alive(): return + self.min_timedelta = datetime.timedelta(minutes=min_timedelta) + self.warning_count = Counter(max_warning_count) logger.info(f"Scheduler watcher start") self.watcher = threading.Thread(target=self.watcher_thread, daemon=True) self.watcher.start() @@ -52,11 +55,11 @@ class SchedulerWatcher: now = datetime.datetime.now() if self.warning_count.current_count > 0: self.warning_count.reset() - self.warning_time = now + datetime.timedelta(minutes=10) + self.warning_time = now + self.min_timedelta logger.info(f"Current task requests to extend the task deadline") else: if self.warning_time - now < datetime.timedelta(minutes=3): - self.warning_time = now + datetime.timedelta(minutes=10) + self.warning_time = now + self.min_timedelta logger.info(f"Current task requests to extend the task deadline") def no_task(self): @@ -70,7 +73,7 @@ class SchedulerWatcher: return self.current_task = task self.warning_count.reset() - self.warning_time = datetime.datetime.now() + datetime.timedelta(minutes=10) + self.warning_time = datetime.datetime.now() + self.min_timedelta def watcher_thread(self): while 1: @@ -83,7 +86,7 @@ class SchedulerWatcher: try: self.warning_count.count_once() logger.warning(f"Current task reached time limit once") - self.warning_time = now + datetime.timedelta(minutes=10) + self.warning_time = now + self.min_timedelta except CounterReachMaxCountException: logger.error(f"Current task reached final time limit, assuming the scheduler is stuck")