(
self, task: asyncio.Task, platform: Platform | None = None
)
| 230 | logger.error(traceback.format_exc()) |
| 231 | |
| 232 | async def _task_wrapper( |
| 233 | self, task: asyncio.Task, platform: Platform | None = None |
| 234 | ) -> None: |
| 235 | # 设置平台状态为运行中 |
| 236 | if platform: |
| 237 | platform.status = PlatformStatus.RUNNING |
| 238 | |
| 239 | try: |
| 240 | await task |
| 241 | except asyncio.CancelledError: |
| 242 | if platform: |
| 243 | platform.status = PlatformStatus.STOPPED |
| 244 | except Exception as e: |
| 245 | error_msg = str(e) |
| 246 | tb_str = traceback.format_exc() |
| 247 | logger.error(f"------- 任务 {task.get_name()} 发生错误: {e}") |
| 248 | for line in tb_str.split("\n"): |
| 249 | logger.error(f"| {line}") |
| 250 | logger.error("-------") |
| 251 | |
| 252 | # 记录错误到平台实例 |
| 253 | if platform: |
| 254 | platform.record_error(error_msg, tb_str) |
| 255 | |
| 256 | async def reload(self, platform_config: dict) -> None: |
| 257 | await self.terminate_platform(platform_config["id"]) |
no test coverage detected