消息异常捕获,防止退出循环
This commit is contained in:
9
robot.py
9
robot.py
@@ -217,7 +217,7 @@ class Robot(Job):
|
|||||||
try:
|
try:
|
||||||
data = await self.ipad_bot.sync_message()
|
data = await self.ipad_bot.sync_message()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.warning(f"获取新消息失败 {e}")
|
self.LOG.error(f"获取新消息失败 {e}")
|
||||||
if e == "用户可能退出":
|
if e == "用户可能退出":
|
||||||
self.LOG.error(f"获取新消息失败 {e},请重启应用重新登录!")
|
self.LOG.error(f"获取新消息失败 {e},请重启应用重新登录!")
|
||||||
self.ipad_running = False
|
self.ipad_running = False
|
||||||
@@ -227,6 +227,7 @@ class Robot(Job):
|
|||||||
data = data.get("AddMsgs")
|
data = data.get("AddMsgs")
|
||||||
if data:
|
if data:
|
||||||
for message in data:
|
for message in data:
|
||||||
|
self.LOG.debug(f"sync_message.处理消息消息内容: {message}")
|
||||||
# 处理消息
|
# 处理消息
|
||||||
try:
|
try:
|
||||||
wxmsg: WxMessage = WxMessage.from_json(message)
|
wxmsg: WxMessage = WxMessage.from_json(message)
|
||||||
@@ -237,7 +238,7 @@ class Robot(Job):
|
|||||||
await self._process_ipad_message(wxmsg)
|
await self._process_ipad_message(wxmsg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.error(f"捕获消息处理异常,继续进行下一个消息处理{e}")
|
self.LOG.error(f"捕获消息处理异常,继续进行下一个消息处理{e}")
|
||||||
continue # 跳过本条消息,继续处理下一条
|
continue
|
||||||
|
|
||||||
# 使用异步睡眠替代忙等待循环
|
# 使用异步睡眠替代忙等待循环
|
||||||
await asyncio.sleep(0.5)
|
await asyncio.sleep(0.5)
|
||||||
@@ -679,7 +680,7 @@ class Robot(Job):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.error(f"xiu_ren_download_task error:{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:
|
try:
|
||||||
receivers = self.gbm.get_group_list()
|
receivers = self.gbm.get_group_list()
|
||||||
if not receivers:
|
if not receivers:
|
||||||
@@ -687,6 +688,6 @@ class Robot(Job):
|
|||||||
for r in receivers:
|
for r in receivers:
|
||||||
if self.gbm.get_group_permission(r, Feature.DAILY_SUMMARY) == PermissionStatus.ENABLED:
|
if self.gbm.get_group_permission(r, Feature.DAILY_SUMMARY) == PermissionStatus.ENABLED:
|
||||||
output = self.message_storage.generate_and_send_ranking(r, self.allContacts)
|
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:
|
except Exception as e:
|
||||||
self.LOG.error(f"SendRanking error:{e}")
|
self.LOG.error(f"SendRanking error:{e}")
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ from playwright.async_api import async_playwright
|
|||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
# linux 下需要安装字体
|
||||||
|
# sudo apt-get install -y fonts-noto-cjk fonts-noto-cjk-extra
|
||||||
|
|
||||||
# 将 Markdown 字符串转换为 HTML
|
# 将 Markdown 字符串转换为 HTML
|
||||||
def md_str_to_html(md_content, output_html):
|
def md_str_to_html(md_content, output_html):
|
||||||
|
|||||||
Reference in New Issue
Block a user