消息异常捕获,防止退出循环

This commit is contained in:
liuwei
2025-05-16 09:42:57 +08:00
parent 3722a164b6
commit 11a3c4ef6b
2 changed files with 7 additions and 4 deletions

View File

@@ -217,7 +217,7 @@ class Robot(Job):
try:
data = await self.ipad_bot.sync_message()
except Exception as e:
self.LOG.warning(f"获取新消息失败 {e}")
self.LOG.error(f"获取新消息失败 {e}")
if e == "用户可能退出":
self.LOG.error(f"获取新消息失败 {e},请重启应用重新登录!")
self.ipad_running = False
@@ -227,6 +227,7 @@ class Robot(Job):
data = data.get("AddMsgs")
if data:
for message in data:
self.LOG.debug(f"sync_message.处理消息消息内容: {message}")
# 处理消息
try:
wxmsg: WxMessage = WxMessage.from_json(message)
@@ -237,7 +238,7 @@ class Robot(Job):
await self._process_ipad_message(wxmsg)
except Exception as e:
self.LOG.error(f"捕获消息处理异常,继续进行下一个消息处理{e}")
continue # 跳过本条消息,继续处理下一条
continue
# 使用异步睡眠替代忙等待循环
await asyncio.sleep(0.5)
@@ -679,7 +680,7 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"xiu_ren_download_task error{e}")
def generate_and_send_ranking(self):
async def generate_and_send_ranking(self):
try:
receivers = self.gbm.get_group_list()
if not receivers:
@@ -687,6 +688,6 @@ class Robot(Job):
for r in receivers:
if self.gbm.get_group_permission(r, Feature.DAILY_SUMMARY) == PermissionStatus.ENABLED:
output = self.message_storage.generate_and_send_ranking(r, self.allContacts)
self.ipad_bot.send_text_message(r, output)
await self.ipad_bot.send_text_message(r, output)
except Exception as e:
self.LOG.error(f"SendRanking error{e}")

View File

@@ -3,6 +3,8 @@ from playwright.async_api import async_playwright
import os
import asyncio
# linux 下需要安装字体
# sudo apt-get install -y fonts-noto-cjk fonts-noto-cjk-extra
# 将 Markdown 字符串转换为 HTML
def md_str_to_html(md_content, output_html):