后端更新
This commit is contained in:
+18
-7
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -21,12 +22,25 @@ from routers.Service import serviceRouter
|
||||
from routers.System import systemRouter
|
||||
from routers.Vision import visionRouter
|
||||
from routers.WS import iot_ws_router
|
||||
from service.RabbitMQ import sentinel_pull_analysis_async
|
||||
from service.RabbitMQ import (
|
||||
mq_client,
|
||||
)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# 应用启动时初始化 MQ
|
||||
await mq_client.init()
|
||||
# 启动消费者
|
||||
await mq_client.start_all_consumer()
|
||||
yield
|
||||
# 应用关闭时关闭 MQ 连接
|
||||
if mq_client._connection:
|
||||
await mq_client._connection.close()
|
||||
|
||||
|
||||
async def ai_lab():
|
||||
app = FastAPI(title="BBIT_AI")
|
||||
|
||||
app = FastAPI(title="BBIT_AI", lifespan=lifespan)
|
||||
origins = [
|
||||
"http://localhost:8091", # Vite dev 默认端口
|
||||
"https://ai.ronsunny.cn:8090",
|
||||
@@ -71,16 +85,13 @@ async def ai_lab():
|
||||
|
||||
|
||||
async def main():
|
||||
|
||||
# 初始化模型
|
||||
YOLOSingleton.init_model()
|
||||
# 主干AI实验室FastAPI服务
|
||||
task_api = asyncio.create_task(ai_lab())
|
||||
# RabbitMQ服务
|
||||
task_mq = asyncio.create_task(sentinel_pull_analysis_async())
|
||||
# 等 HTTP 服务启动后再启动 MQTT
|
||||
task_mqtt = asyncio.create_task(mqtt_client_runner())
|
||||
await asyncio.gather(task_api, task_mq, task_mqtt)
|
||||
await asyncio.gather(task_api, task_mqtt)
|
||||
|
||||
# MCP服务-ailab
|
||||
# endpoint_url_ai_lab = "wss://ai.ronsunny.cn:8090/aimcp/mcp_endpoint/mcp/?token=TsSP9lBq6Oa1WMkachHoS2TtNt4GKV/Gli24pk5Rjpk%3D"
|
||||
|
||||
Reference in New Issue
Block a user