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

add: disable task which has caused many errors already

This commit is contained in:
0O0o0oOoO00
2025-09-21 13:48:20 +08:00
parent 52b060ec18
commit 26cc11c9de
12 changed files with 136 additions and 2 deletions

40
alas.py
View File

@@ -609,6 +609,26 @@ class FailedTaskCounter:
self.tasks[task].reset()
class RepeatedFailedTaskCounter:
def __init__(self, max_retries):
self.max_retries = max_retries
if max_retries is None:
self.counter = None
elif max_retries <= 0:
self.counter = None
else:
self.counter = MaxCounter(self.max_retries)
def count_once(self) -> bool:
if self.counter is None:
return False
return self.counter.count_once(throw=False)
def reset(self):
if self.counter is not None:
self.counter.reset()
class AzurLaneAutoScript(AzurLaneAutoScript):
def __init__(self, config_name='alas'):
self.pre_init()
@@ -628,6 +648,10 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
self.failed_task_counter = FailedTaskCounter(self.max_retry_times_for_same_task_failed)
self.is_enabled_disable_task = full_config.Restart_CloseTask_Enable
self.max_error_occurs = full_config.Restart_CloseTask_MaxErrorOccur if self.is_enabled_disable_task else None
self.repeated_failed_task_counter = RepeatedFailedTaskCounter(self.max_error_occurs)
def pre_init(self):
from PIL import Image
Image.init()
@@ -1001,7 +1025,21 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
title=f"Alas <{self.config_name}> crashed",
content=f"<{self.config_name}> RequestHumanTakeover\nTask `{task}` failed {self.max_retry_times_for_same_task_failed} or more times.",
)
exit(1)
if self.is_enabled_disable_task:
if not self.repeated_failed_task_counter.count_once():
msg = "This task has caused many errors already, disable it"
logger.warning(msg)
self.config.disable_task(task)
self.failed_task_counter.reset_task(task)
self.repeated_failed_task_counter.reset()
handle_notify(
self.config.Error_OnePushConfig,
title=f"Alas <{self.config_name}> disabled `{task}`",
content=msg,
)
else:
exit(1)
if success:
self.failed_task_counter.reset_task(task)

View File

@@ -150,6 +150,10 @@
"FatalErrorRestart": false,
"MaxRetryTimesForSameTaskFailed": 5
},
"CloseTask": {
"Enable": false,
"MaxErrorOccur": 2
},
"InstanceRestart": {
"Enable": false,
"MaxRetryTimes": 5,

View File

@@ -651,6 +651,16 @@
"value": 5
}
},
"CloseTask": {
"Enable": {
"type": "checkbox",
"value": false
},
"MaxErrorOccur": {
"type": "input",
"value": 2
}
},
"InstanceRestart": {
"Enable": {
"type": "checkbox",

View File

@@ -984,4 +984,10 @@ GuildCoin:
OthersLogin:
Enable: false
Interval: 180
Notify: true
Notify: true
# ==================== CloseTask ====================
CloseTask:
Enable: false
MaxErrorOccur: 2

View File

@@ -23,6 +23,7 @@ Alas:
- Scheduler
- SchedulerWatcher
- GameRestart
- CloseTask
- InstanceRestart
- OthersLogin

View File

@@ -841,3 +841,16 @@ class AzurLaneConfig(AzurLaneConfig):
and "GemsFarming" in pending_tasks \
and "OpsiHazard1Leveling" in pending_tasks:
self.pending_task.reverse()
def get(self, path, default=None):
return deep_get(self.data, path, default)
def set(self, path, value):
self.modified[path] = value
self.update()
def enable_task(self, task):
self.set(f"{task}.Scheduler.Enable", True)
def disable_task(self, task):
self.set(f"{task}.Scheduler.Enable", False)

View File

@@ -626,5 +626,9 @@ class GeneratedConfig:
OthersLogin_Interval = 180
OthersLogin_Notify = True
# Group `CloseTask`
CloseTask_Enable = False
CloseTask_MaxErrorOccur = 2
# Group `Storage`
Storage_Storage = {}

View File

@@ -104,6 +104,8 @@ class FullGeneratedConfig:
Restart_SchedulerWatcher_WarningCount = None
Restart_GameRestart_FatalErrorRestart = None
Restart_GameRestart_MaxRetryTimesForSameTaskFailed = None
Restart_CloseTask_Enable = None
Restart_CloseTask_MaxErrorOccur = None
Restart_InstanceRestart_Enable = None
Restart_InstanceRestart_MaxRetryTimes = None
Restart_InstanceRestart_Notify = None

View File

@@ -3412,6 +3412,20 @@
"help": "OthersLogin.Notify.help"
}
},
"CloseTask": {
"_info": {
"name": "CloseTask._info.name",
"help": "CloseTask._info.help"
},
"Enable": {
"name": "CloseTask.Enable.name",
"help": "CloseTask.Enable.help"
},
"MaxErrorOccur": {
"name": "CloseTask.MaxErrorOccur.name",
"help": "CloseTask.MaxErrorOccur.help"
}
},
"Storage": {
"_info": {
"name": "Task status",

View File

@@ -3412,6 +3412,20 @@
"help": "OthersLogin.Notify.help"
}
},
"CloseTask": {
"_info": {
"name": "CloseTask._info.name",
"help": "CloseTask._info.help"
},
"Enable": {
"name": "CloseTask.Enable.name",
"help": "CloseTask.Enable.help"
},
"MaxErrorOccur": {
"name": "CloseTask.MaxErrorOccur.name",
"help": "CloseTask.MaxErrorOccur.help"
}
},
"Storage": {
"_info": {
"name": "Storage._info.name",

View File

@@ -3412,6 +3412,20 @@
"help": ""
}
},
"CloseTask": {
"_info": {
"name": "关闭任务",
"help": "修改以下的配置后要重新启动Alas实例"
},
"Enable": {
"name": "启用",
"help": ""
},
"MaxErrorOccur": {
"name": "当Alas重复出错 X 次后关闭出错的任务",
"help": ""
}
},
"Storage": {
"_info": {
"name": "任务状态",

View File

@@ -3412,6 +3412,20 @@
"help": "OthersLogin.Notify.help"
}
},
"CloseTask": {
"_info": {
"name": "CloseTask._info.name",
"help": "CloseTask._info.help"
},
"Enable": {
"name": "CloseTask.Enable.name",
"help": "CloseTask.Enable.help"
},
"MaxErrorOccur": {
"name": "CloseTask.MaxErrorOccur.name",
"help": "CloseTask.MaxErrorOccur.help"
}
},
"Storage": {
"_info": {
"name": "任務狀態",