fix: 采集循环单轮容错 + 事件流水目录自动创建(Linux 首启致命bug)
This commit is contained in:
@@ -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
|
||||||
self.emit(rec)
|
try:
|
||||||
|
self.emit(rec)
|
||||||
|
except Exception:
|
||||||
|
pass # 回调异常不允许杀死采集循环
|
||||||
|
|
||||||
# ---------- 实证先验(skill 注入) ----------
|
# ---------- 实证先验(skill 注入) ----------
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -47,7 +47,13 @@ async def collector_task(_app):
|
|||||||
|
|
||||||
async def poll():
|
async def poll():
|
||||||
while True:
|
while True:
|
||||||
await loop.run_in_executor(None, collector.one_cycle)
|
try:
|
||||||
|
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())
|
||||||
|
|||||||
Reference in New Issue
Block a user