mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 07:39:25 +08:00
adj: separate the settings of the scheduler watcher
This commit is contained in:
7
alas.py
7
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()
|
||||
|
||||
@@ -190,8 +190,12 @@
|
||||
"AttemptsToRestart": 114514,
|
||||
"NotifyWhenAutoRestart": false
|
||||
},
|
||||
"SchedulerWatcher": {
|
||||
"Enable": false,
|
||||
"TimeDelta": 10,
|
||||
"WarningCount": 3
|
||||
},
|
||||
"InstanceRestart": {
|
||||
"EnableSchedulerWatcher": false,
|
||||
"Enabled": false,
|
||||
"AttemptsToRestart": 114514,
|
||||
"NotifyWhenAutoRestart": false,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -26,6 +26,7 @@ Alas:
|
||||
Restart:
|
||||
- Scheduler
|
||||
- AutoRestart
|
||||
- SchedulerWatcher
|
||||
- InstanceRestart
|
||||
- ExitWhenMaintenance
|
||||
OthersLogin:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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": ""
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user