fix: improve douyu scheduled check error logging
This commit is contained in:
@@ -495,6 +495,13 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
async_job.every_minutes(self._check_interval)(self._scheduled_unified_check_job)
|
||||
async_job.every_minutes(5)(self._scheduled_daily_report_tick)
|
||||
|
||||
@staticmethod
|
||||
def _format_exception(exc: Exception) -> str:
|
||||
message = str(exc).strip()
|
||||
if message:
|
||||
return f"{type(exc).__name__}: {message}"
|
||||
return type(exc).__name__
|
||||
|
||||
async def _scheduled_unified_check_job(self):
|
||||
"""统一检查直播和鱼吧动态"""
|
||||
await self._scheduled_check_job()
|
||||
@@ -690,6 +697,7 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
"Referer": f"https://www.douyu.com/{room_id}"
|
||||
}
|
||||
async with session.get(url, headers=headers, timeout=aiohttp.ClientTimeout(total=10)) as resp:
|
||||
resp.raise_for_status()
|
||||
data = await resp.json(content_type=None)
|
||||
room_info = data.get("room", {}) if isinstance(data, dict) else {}
|
||||
show_status = room_info.get("show_status")
|
||||
@@ -734,14 +742,18 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
logger.info(f"检测到持续直播状态,补偿启动斗鱼弹幕记录({room_id})")
|
||||
self._start_danmu_record(room_id)
|
||||
except Exception as e:
|
||||
logger.error(f"补偿启动斗鱼弹幕记录失败({room_id}): {e}")
|
||||
logger.exception(
|
||||
f"补偿启动斗鱼弹幕记录失败({room_id}): {self._format_exception(e)}"
|
||||
)
|
||||
continue
|
||||
await asyncio.sleep(0.1)
|
||||
except Exception as e:
|
||||
logger.error(f"斗鱼检查失败: {e}")
|
||||
logger.exception(
|
||||
f"斗鱼检查失败(room_id={room_id}): {self._format_exception(e)}"
|
||||
)
|
||||
continue
|
||||
except Exception as e:
|
||||
logger.error(f"斗鱼定时任务异常: {e}")
|
||||
logger.exception(f"斗鱼定时任务异常: {self._format_exception(e)}")
|
||||
|
||||
async def _notify_groups_live(self, room_id: str, nickname: str, room_name: str, thumb_url: str):
|
||||
groups = self.redis_manager.groups_for_room(room_id)
|
||||
@@ -815,6 +827,7 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
}
|
||||
async with session.get(self._yuba_api, headers=headers, params=params,
|
||||
timeout=aiohttp.ClientTimeout(total=10)) as resp:
|
||||
resp.raise_for_status()
|
||||
data = await resp.json(content_type=None)
|
||||
|
||||
if data.get("error") != 0:
|
||||
@@ -860,10 +873,12 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
|
||||
await asyncio.sleep(0.5)
|
||||
except Exception as e:
|
||||
logger.error(f"检查斗鱼鱼吧 ({hash_id}) 失败: {e}")
|
||||
logger.exception(
|
||||
f"检查斗鱼鱼吧({hash_id})失败: {self._format_exception(e)}"
|
||||
)
|
||||
continue
|
||||
except Exception as e:
|
||||
logger.error(f"斗鱼鱼吧定时任务异常: {e}")
|
||||
logger.exception(f"斗鱼鱼吧定时任务异常: {self._format_exception(e)}")
|
||||
|
||||
async def _notify_groups_yuba(self, hash_id: str, nickname: str, content: str, url: str,
|
||||
publish_time: str = "未知时间"):
|
||||
|
||||
Reference in New Issue
Block a user