refactor: 替换 asyncio.get_event_loop 为 get_running_loop 并优化会话卡片
- 将多处 asyncio.get_event_loop() 替换为更安全的 asyncio.get_running_loop() - 重构 Feishu 卡片功能,新增 build_sessions_card 方法显示所有会话 - 优化文件路径处理逻辑,支持绝对路径和相对路径 - 在健康检查接口中添加 pending_requests 计数 - 更新会话状态命令以支持卡片显示
This commit is contained in:
+3
-2
@@ -43,6 +43,7 @@ def create_app(router_secret: Optional[str] = None) -> FastAPI:
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
from router.rpc import get_pending_count
|
||||
nodes = registry.list_nodes()
|
||||
online_nodes = [n for n in nodes if n["status"] == "online"]
|
||||
return {
|
||||
@@ -50,7 +51,7 @@ def create_app(router_secret: Optional[str] = None) -> FastAPI:
|
||||
"nodes": nodes,
|
||||
"online_nodes": len(online_nodes),
|
||||
"total_nodes": len(nodes),
|
||||
"pending_requests": 0,
|
||||
"pending_requests": get_pending_count(),
|
||||
}
|
||||
|
||||
@app.get("/nodes")
|
||||
@@ -64,7 +65,7 @@ def create_app(router_secret: Optional[str] = None) -> FastAPI:
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
import asyncio
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = asyncio.get_running_loop()
|
||||
start_websocket_client(loop)
|
||||
logger.info("Router started")
|
||||
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ async def forward(
|
||||
raise RuntimeError(f"Node not connected: {node_id}")
|
||||
|
||||
request_id = str(uuid.uuid4())
|
||||
future: asyncio.Future[str] = asyncio.get_event_loop().create_future()
|
||||
future: asyncio.Future[str] = asyncio.get_running_loop().create_future()
|
||||
_pending_requests[request_id] = future
|
||||
|
||||
request = ForwardRequest(
|
||||
|
||||
Reference in New Issue
Block a user