完成线程启动训练并以websocket的方式进行发送shell

This commit is contained in:
2025-03-10 17:42:56 +08:00
parent b4b1085403
commit 7d736c4ac4
9 changed files with 97 additions and 36 deletions

View File

@ -44,17 +44,17 @@ my_app.include_router(web_socket, prefix="/ws", tags=["websocket管理"])
# fastapi定时执行任务
async def periodic_task():
async def serve_info_task():
while True:
server_json = get_server_json()
await room_manager.send_to_room('server-info', server_json)
await asyncio.sleep(2) # 每 10 秒执行
await asyncio.sleep(5) # 每 5 秒执行
@my_app.on_event("startup")
async def start_periodic_task():
# 在后台启动异步任务
asyncio.create_task(periodic_task())
asyncio.create_task(serve_info_task())