fix: 采集循环单轮容错 + 事件流水目录自动创建(Linux 首启致命bug)

This commit is contained in:
lookt
2026-09-15 20:26:01 +08:00
parent a5ecda3ef1
commit 3fafd08545
2 changed files with 12 additions and 2 deletions
+4
View File
@@ -42,6 +42,7 @@ class TimelineCollector:
self.emit = emit # callable(dict) self.emit = emit # callable(dict)
self.db_path = str(db_path or DB) self.db_path = str(db_path or DB)
self.state = {'date': datetime.now().strftime('%Y-%m-%d')} self.state = {'date': datetime.now().strftime('%Y-%m-%d')}
FEED.parent.mkdir(parents=True, exist_ok=True) # 事件流水目录
self.priors = {} self.priors = {}
self._load_priors() self._load_priors()
@@ -59,7 +60,10 @@ class TimelineCollector:
f.write(json.dumps(rec, ensure_ascii=False) + '\n') f.write(json.dumps(rec, ensure_ascii=False) + '\n')
except OSError: except OSError:
pass pass
try:
self.emit(rec) self.emit(rec)
except Exception:
pass # 回调异常不允许杀死采集循环
# ---------- 实证先验(skill 注入) ---------- # ---------- 实证先验(skill 注入) ----------
+6
View File
@@ -47,7 +47,13 @@ async def collector_task(_app):
async def poll(): async def poll():
while True: while True:
try:
await loop.run_in_executor(None, collector.one_cycle) await loop.run_in_executor(None, collector.one_cycle)
except asyncio.CancelledError:
raise
except Exception:
import traceback
traceback.print_exc()
await asyncio.sleep(60) await asyncio.sleep(60)
task = asyncio.create_task(poll()) task = asyncio.create_task(poll())