1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-14 11:59:24 +08:00

adj: separate the settings of the scheduler watcher

This commit is contained in:
0O0o0oOoO00
2025-08-09 20:08:57 +08:00
parent 3e7c13df3b
commit ae1e32aef2
11 changed files with 113 additions and 29 deletions

View File

@@ -796,8 +796,11 @@ class AzurLaneAutoScript:
exit(0) exit(0)
def loop(self): def loop(self):
if deep_get(self.config.data, "Restart.InstanceRestart.EnableSchedulerWatcher", False): if deep_get(self.config.data, "Restart.SchedulerWatcher.Enable", False):
self.scheduler_watcher.start_watch() 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: if self.is_azur:
CrackResource(self.config, self.device).ensure() CrackResource(self.config, self.device).ensure()

View File

@@ -190,8 +190,12 @@
"AttemptsToRestart": 114514, "AttemptsToRestart": 114514,
"NotifyWhenAutoRestart": false "NotifyWhenAutoRestart": false
}, },
"SchedulerWatcher": {
"Enable": false,
"TimeDelta": 10,
"WarningCount": 3
},
"InstanceRestart": { "InstanceRestart": {
"EnableSchedulerWatcher": false,
"Enabled": false, "Enabled": false,
"AttemptsToRestart": 114514, "AttemptsToRestart": 114514,
"NotifyWhenAutoRestart": false, "NotifyWhenAutoRestart": false,

View File

@@ -815,11 +815,21 @@
"value": false "value": false
} }
}, },
"InstanceRestart": { "SchedulerWatcher": {
"EnableSchedulerWatcher": { "Enable": {
"type": "checkbox", "type": "checkbox",
"value": false "value": false
}, },
"TimeDelta": {
"type": "input",
"value": 10
},
"WarningCount": {
"type": "input",
"value": 3
}
},
"InstanceRestart": {
"Enabled": { "Enabled": {
"type": "checkbox", "type": "checkbox",
"value": false "value": false

View File

@@ -1285,8 +1285,11 @@ AutoRestart:
NotifyWhenAutoRestart: NotifyWhenAutoRestart:
type: checkbox type: checkbox
value: false value: false
SchedulerWatcher:
Enable: false
TimeDelta: 10
WarningCount: 3
InstanceRestart: InstanceRestart:
EnableSchedulerWatcher: false
Enabled: Enabled:
type: checkbox type: checkbox
value: false value: false

View File

@@ -26,6 +26,7 @@ Alas:
Restart: Restart:
- Scheduler - Scheduler
- AutoRestart - AutoRestart
- SchedulerWatcher
- InstanceRestart - InstanceRestart
- ExitWhenMaintenance - ExitWhenMaintenance
OthersLogin: OthersLogin:

View File

@@ -774,8 +774,12 @@ class GeneratedConfig:
AutoRestart_AttemptsToRestart = 114514 AutoRestart_AttemptsToRestart = 114514
AutoRestart_NotifyWhenAutoRestart = False AutoRestart_NotifyWhenAutoRestart = False
# Group `SchedulerWatcher`
SchedulerWatcher_Enable = False
SchedulerWatcher_TimeDelta = 10
SchedulerWatcher_WarningCount = 3
# Group `InstanceRestart` # Group `InstanceRestart`
InstanceRestart_EnableSchedulerWatcher = False
InstanceRestart_Enabled = False InstanceRestart_Enabled = False
InstanceRestart_AttemptsToRestart = 114514 InstanceRestart_AttemptsToRestart = 114514
InstanceRestart_NotifyWhenAutoRestart = False InstanceRestart_NotifyWhenAutoRestart = False

View File

@@ -4240,15 +4240,29 @@
"help": "AutoRestart.NotifyWhenAutoRestart.help" "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": { "InstanceRestart": {
"_info": { "_info": {
"name": "InstanceRestart._info.name", "name": "InstanceRestart._info.name",
"help": "InstanceRestart._info.help" "help": "InstanceRestart._info.help"
}, },
"EnableSchedulerWatcher": {
"name": "InstanceRestart.EnableSchedulerWatcher.name",
"help": "InstanceRestart.EnableSchedulerWatcher.help"
},
"Enabled": { "Enabled": {
"name": "InstanceRestart.Enabled.name", "name": "InstanceRestart.Enabled.name",
"help": "InstanceRestart.Enabled.help" "help": "InstanceRestart.Enabled.help"

View File

@@ -4240,15 +4240,29 @@
"help": "AutoRestart.NotifyWhenAutoRestart.help" "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": { "InstanceRestart": {
"_info": { "_info": {
"name": "InstanceRestart._info.name", "name": "InstanceRestart._info.name",
"help": "InstanceRestart._info.help" "help": "InstanceRestart._info.help"
}, },
"EnableSchedulerWatcher": {
"name": "InstanceRestart.EnableSchedulerWatcher.name",
"help": "InstanceRestart.EnableSchedulerWatcher.help"
},
"Enabled": { "Enabled": {
"name": "InstanceRestart.Enabled.name", "name": "InstanceRestart.Enabled.name",
"help": "InstanceRestart.Enabled.help" "help": "InstanceRestart.Enabled.help"

View File

@@ -4240,15 +4240,29 @@
"help": "因出错而自动重启时通知,不建议开启,因为可能会很烦" "help": "因出错而自动重启时通知,不建议开启,因为可能会很烦"
} }
}, },
"SchedulerWatcher": {
"_info": {
"name": "调度器监视器",
"help": "如果要开启此功能则建议开启自动实例重启\n注意: 修改以下的配置后要重新启动Alas实例"
},
"Enable": {
"name": "启用",
"help": ""
},
"TimeDelta": {
"name": "单次时限(分钟)",
"help": ""
},
"WarningCount": {
"name": "最大警告次数",
"help": ""
}
},
"InstanceRestart": { "InstanceRestart": {
"_info": { "_info": {
"name": "重启Alas实例", "name": "重启Alas实例",
"help": "" "help": ""
}, },
"EnableSchedulerWatcher": {
"name": "调度器监视器",
"help": "如果要开启此功能则建议开启自动实例重启\n注意: 此选项修改后要重新启动Alas"
},
"Enabled": { "Enabled": {
"name": "启用", "name": "启用",
"help": "" "help": ""

View File

@@ -4240,15 +4240,29 @@
"help": "AutoRestart.NotifyWhenAutoRestart.help" "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": { "InstanceRestart": {
"_info": { "_info": {
"name": "InstanceRestart._info.name", "name": "InstanceRestart._info.name",
"help": "InstanceRestart._info.help" "help": "InstanceRestart._info.help"
}, },
"EnableSchedulerWatcher": {
"name": "InstanceRestart.EnableSchedulerWatcher.name",
"help": "InstanceRestart.EnableSchedulerWatcher.help"
},
"Enabled": { "Enabled": {
"name": "InstanceRestart.Enabled.name", "name": "InstanceRestart.Enabled.name",
"help": "InstanceRestart.Enabled.help" "help": "InstanceRestart.Enabled.help"

View File

@@ -31,17 +31,20 @@ class SchedulerWatcher:
def __init__(self): def __init__(self):
self.alas_obj = None self.alas_obj = None
self.watcher: threading.Thread = None self.watcher: threading.Thread = None
self.warning_count = Counter(3) self.warning_count = None
self.warning_time = None self.warning_time = None
self.current_task = None self.current_task = None
self.min_timedelta = None
def set_alas_obj(self, alas_obj): def set_alas_obj(self, alas_obj):
self.alas_obj = 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 not None:
if self.watcher.is_alive(): if self.watcher.is_alive():
return return
self.min_timedelta = datetime.timedelta(minutes=min_timedelta)
self.warning_count = Counter(max_warning_count)
logger.info(f"Scheduler watcher start") logger.info(f"Scheduler watcher start")
self.watcher = threading.Thread(target=self.watcher_thread, daemon=True) self.watcher = threading.Thread(target=self.watcher_thread, daemon=True)
self.watcher.start() self.watcher.start()
@@ -52,11 +55,11 @@ class SchedulerWatcher:
now = datetime.datetime.now() now = datetime.datetime.now()
if self.warning_count.current_count > 0: if self.warning_count.current_count > 0:
self.warning_count.reset() 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") logger.info(f"Current task requests to extend the task deadline")
else: else:
if self.warning_time - now < datetime.timedelta(minutes=3): 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") logger.info(f"Current task requests to extend the task deadline")
def no_task(self): def no_task(self):
@@ -70,7 +73,7 @@ class SchedulerWatcher:
return return
self.current_task = task self.current_task = task
self.warning_count.reset() 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): def watcher_thread(self):
while 1: while 1:
@@ -83,7 +86,7 @@ class SchedulerWatcher:
try: try:
self.warning_count.count_once() self.warning_count.count_once()
logger.warning(f"Current task reached time limit 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: except CounterReachMaxCountException:
logger.error(f"Current task reached final time limit, assuming the scheduler is stuck") logger.error(f"Current task reached final time limit, assuming the scheduler is stuck")