AI事件重复推送

This commit is contained in:
quantulr
2024-03-21 14:18:01 +08:00
parent 9e03e6edcc
commit 28c6b44076
8 changed files with 175 additions and 6 deletions

33
hik_push/subscribe.py Normal file
View File

@ -0,0 +1,33 @@
import json
import uvicorn
from fastapi import FastAPI, BackgroundTasks
from redis import asyncio as aioredis
app = FastAPI()
async def add_stream(data: dict):
# redis = await aioredis.Redis(host="127.0.0.1", port=7019, password="SMHdFrlK")
redis = await aioredis.Redis(host="127.0.0.1")
await redis.lpush("hik-sub-event", json.dumps(data))
await redis.close()
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.post("/eventRcv")
async def event_rcv(data: dict, background_tasks: BackgroundTasks):
background_tasks.add_task(add_stream, data)
return {"msg": "success"}
def run_app():
uvicorn.run(app=app, host="0.0.0.0", port=8000)
if __name__ == "__main__":
run_app()