Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class EmulatorRuntimePolicy:
resource_path: Path


class EmulatorStartupError(RuntimeError):
"""模拟器的安全启动恢复已结束,调用方不得叠加任务重试。"""


class DeviceStatus(IntEnum):
ONLINE = 0
"""设备在线"""
Expand Down
4 changes: 3 additions & 1 deletion app/task/BAAH/AutoProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)
from app.core.ws import protocol
from app.models.config import BAAHConfig, BAAHPlanConfig, BAAHUserConfig
from app.models.emulator import DeviceBase
from app.models.emulator import DeviceBase, EmulatorStartupError
from app.models.notification import LocalNotice
from app.models.schema import HistoryWrite, WSTaskNoticeData
from app.models.task import LogRecord, ScriptItem, UserItem
Expand Down Expand Up @@ -443,6 +443,8 @@ async def _ensure_emulator_online(self) -> bool:
device_info = await self.emulator_manager.open(
str(self.script_config.Emulator.Index)
)
except EmulatorStartupError:
raise
except Exception as e:
logger.opt(exception=True).warning(f"启动模拟器失败: {e}")
await self.handle_pre_script_error("启动模拟器失败", e)
Expand Down
4 changes: 3 additions & 1 deletion app/task/MAA/AutoProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
MaaConfig,
MaaUserConfig,
)
from app.models.emulator import DeviceBase, DeviceInfo
from app.models.emulator import DeviceBase, DeviceInfo, EmulatorStartupError
from app.models.notification import LocalNotice, NotificationImage
from app.models.schema import (
HistoryAggregationItem,
Expand Down Expand Up @@ -1485,6 +1485,8 @@ async def main_task(self):
**mod_avd_open_kwargs(self.emulator_manager, allowed=True),
)
self.emulator_info = emulator_info
except EmulatorStartupError:
raise
except Exception as e:
logger.opt(exception=True).warning(
f"账号: {self.cur_user_uid} - 模拟器启动失败: {e}"
Expand Down
4 changes: 3 additions & 1 deletion app/task/MaaEnd/AutoProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from app.core.history import aggregate_data
from app.core.ws import protocol
from app.models.config import MaaEndConfig, MaaEndUserConfig
from app.models.emulator import DeviceBase, DeviceInfo
from app.models.emulator import DeviceBase, DeviceInfo, EmulatorStartupError
from app.models.notification import LocalNotice
from app.models.schema import HistoryAggregationItem, HistoryWrite, WSTaskNoticeData
from app.models.task import LogRecord, ScriptItem
Expand Down Expand Up @@ -1624,6 +1624,8 @@ async def main_task(self):
self.script_config.Game.EmulatorIndex,
"" if cloud_adb else "com.hypergryph.endfield",
)
except EmulatorStartupError:
raise
except Exception as e:
# 启动阶段失败后游戏状态不再可信:清除保留标记,避免下一轮
# 启动沿用 preserve_running_game 跳过启动器游戏设置
Expand Down
6 changes: 4 additions & 2 deletions app/task/MaaFW/tools/embedded/runner_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)
from app.core.notify.task_content import screenshot_entries as screenshot_entries
from app.core.ws import protocol
from app.models.emulator import DeviceBase, DeviceInfo
from app.models.emulator import DeviceBase, DeviceInfo, EmulatorStartupError
from app.models.notification import LocalNotice
from app.models.schema import (
HistoryAttachmentInput,
Expand Down Expand Up @@ -916,7 +916,9 @@ async def main_task(self) -> None:
else f"MaaFW 运行异常: {exc}"
)
self._append_log(message, warning=True)
unretryable = _is_unretryable_failure(message)
unretryable = isinstance(
exc, EmulatorStartupError
) or _is_unretryable_failure(message)
self._record_attempt(
index + 1,
[],
Expand Down
9 changes: 8 additions & 1 deletion app/task/SRC/AutoProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
)
from app.core.ws import protocol
from app.models.config import SrcConfig, SrcUserConfig
from app.models.emulator import DeviceBase, DeviceInfo, DeviceStatus
from app.models.emulator import (
DeviceBase,
DeviceInfo,
DeviceStatus,
EmulatorStartupError,
)
from app.models.notification import LocalNotice
from app.models.schema import HistoryAggregationItem, HistoryWrite, WSTaskNoticeData
from app.models.task import LogRecord, ScriptItem
Expand Down Expand Up @@ -227,6 +232,8 @@ async def main_task(self):
self.script_config.Emulator.Index,
STARRAIL_PACKAGE_NAME[self.cur_user_config.Info.Server],
)
except EmulatorStartupError:
raise
except Exception as e:
if not await self.handle_pre_src_error("模拟器启动失败", e):
return
Expand Down
16 changes: 16 additions & 0 deletions app/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
WhimboxConfig,
ZzzOdConfig,
)
from app.models.emulator import EmulatorStartupError
from app.models.task import LogRecord, ScriptItem, TaskExecuteBase, UserItem
from app.services import execute_script_task
from app.task.failure_capture_core import FailureCapture
Expand Down Expand Up @@ -270,6 +271,21 @@ async def _run_main_task(self) -> None:
try:
async with timeout:
await self.main_task()
except EmulatorStartupError as e:
# 模拟器已完成有限恢复;结束本账号本次尝试,由既有生命周期执行收尾。
message = f"模拟器启动失败: {e}"
user = self.cur_user_item
await user.set_state(status="异常")
if user.log_record:
record = user.log_record[max(user.log_record)]
else:
record = await user.add_log_record(
datetime.now().astimezone(), LogRecord()
)
await record.set_state(status=message)
await record.append_content(message)
await self.script_info.set_log(message)
await self.on_crash(e)
except TimeoutError:
# 脚本内部的 TimeoutError 仍交给原异常流程处理。
if not timeout.expired():
Expand Down
Loading
Loading