mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 20:01:04 +00:00
fix: 修复插件任务生命周期管理,避免用户困惑的报错行为 (#125)
- 修复 'NoneType' 报错 (Fix #125): 引入插件终止标志位并完善任务生命周期清理逻辑。 - 强化资源清理:重载时主动取消并等待所有运行中的异步任务(包括手动分析、自动调度和依赖安装),移除危险的属性置空操作,彻底消除重载时的属性访问竞态。
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
QQ群日常分析插件 - 源代码包
|
||||
群日常分析插件 - 源代码包
|
||||
|
||||
本包包含插件的核心实现,采用 DDD (领域驱动设计) 架构:
|
||||
- application: 应用层 - 编排领域服务,处理用例
|
||||
|
||||
@@ -531,7 +531,7 @@
|
||||
{{quotes_html | safe}}
|
||||
</div>
|
||||
<div class="footer">
|
||||
由 AstrBot QQ群日常分析插件 生成 | {{current_datetime}}<br>
|
||||
由 AstrBot 群日常分析插件 生成 | {{current_datetime}}<br>
|
||||
SXP-Simon/astrbot_plugin_qq_group_daily_analysis<br>
|
||||
<span style="opacity: 0.7;">AI分析消耗:{{total_tokens}} tokens (输入: {{prompt_tokens}}, 输出: {{completion_tokens}})</span>
|
||||
</div>
|
||||
|
||||
@@ -825,7 +825,7 @@
|
||||
|
||||
<footer>
|
||||
<div class="footer-row">
|
||||
<div>CRT_EXPORT_CHANNEL // QQ群日常分析插件</div>
|
||||
<div>CRT_EXPORT_CHANNEL // AstrBot 群日常分析插件</div>
|
||||
<div class="footer-author">SXP-Simon / astrbot_plugin_qq_group_daily_analysis</div>
|
||||
</div>
|
||||
<div class="footer-row">
|
||||
|
||||
@@ -51,6 +51,7 @@ class AutoScheduler:
|
||||
|
||||
# Cache: group_id -> group_name (populated lazily)
|
||||
self._group_name_cache: dict[str, str] = {}
|
||||
self._terminating = False # 终止标志位
|
||||
|
||||
def set_bot_instance(self, bot_instance):
|
||||
"""设置bot实例(保持向后兼容)"""
|
||||
@@ -269,6 +270,7 @@ class AutoScheduler:
|
||||
|
||||
def unschedule_jobs(self, context):
|
||||
"""取消定时任务"""
|
||||
self._terminating = True
|
||||
if (
|
||||
not context
|
||||
or not hasattr(context, "cron_manager")
|
||||
@@ -343,6 +345,8 @@ class AutoScheduler:
|
||||
|
||||
async def _run_auto_analysis(self):
|
||||
"""执行传统自动分析 - 并发处理所有群聊"""
|
||||
if self._terminating:
|
||||
return
|
||||
try:
|
||||
logger.info("开始执行自动群聊分析(并发模式)")
|
||||
|
||||
@@ -424,6 +428,9 @@ class AutoScheduler:
|
||||
trace_id = TraceContext.generate(prefix="group", group_name=group_name)
|
||||
TraceContext.set(trace_id)
|
||||
|
||||
if self._terminating:
|
||||
return
|
||||
|
||||
logger.info(
|
||||
f"开始为群 {group_id} 执行自动分析 (Platform: {target_platform_id or 'Auto'})"
|
||||
)
|
||||
@@ -473,9 +480,11 @@ class AutoScheduler:
|
||||
# ================================================================
|
||||
|
||||
async def _run_incremental_analysis(self):
|
||||
"""执行增量分析 - 为所有启用的群聊执行一次增量分析批次"""
|
||||
"""执行增量分析任务 - 并发处理模式"""
|
||||
if self._terminating:
|
||||
return
|
||||
try:
|
||||
logger.info("开始执行增量分析(交错并发模式)")
|
||||
logger.info("开始执行自动增量分析(并发模式)")
|
||||
|
||||
enabled_targets = await self._get_enabled_targets()
|
||||
|
||||
@@ -586,6 +595,9 @@ class AutoScheduler:
|
||||
trace_id = TraceContext.generate(prefix="incr", group_name=group_name)
|
||||
TraceContext.set(trace_id)
|
||||
|
||||
if self._terminating:
|
||||
return
|
||||
|
||||
logger.info(
|
||||
f"开始为群 {group_id} 执行增量分析 "
|
||||
f"(Platform: {target_platform_id or 'Auto'})"
|
||||
|
||||
Reference in New Issue
Block a user