添加--添加测试用websocket地址, 修改--修改同步机器人状态逻辑
This commit is contained in:
parent
6e81cafcf3
commit
d45321ab6f
@ -59,8 +59,9 @@ class EventSyncService:
|
||||
# 修改在线状态
|
||||
if self.robot_dict[message["robotId"]].onlineStatus != message["onlineStatus"]:
|
||||
print(f"开始同步机器人状态")
|
||||
await self._update_robot_online_status(self.robot_dict[message["robotId"]])
|
||||
self.robot_dict[message["robotId"]].onlineStatus = message["onlineStatus"]
|
||||
await self._update_robot_online_status(self.robot_dict[message["robotId"]])
|
||||
|
||||
# 新增机器人消息
|
||||
else:
|
||||
await self._add_robot(message)
|
||||
@ -88,13 +89,19 @@ class EventSyncService:
|
||||
"""更新机器人在线状态"""
|
||||
try:
|
||||
async with async_session() as session:
|
||||
# print(robot.onlineStatus)
|
||||
update_stmt = (
|
||||
update(Robot).where(Robot.robotId == robot.robotId).values(
|
||||
onlineStatus = robot.onlineStatus
|
||||
onlineStatus = robot.onlineStatus,
|
||||
updateTime = datetime.now()
|
||||
)
|
||||
)
|
||||
# print(repr(update_stmt))
|
||||
await session.execute(update_stmt)
|
||||
await session.commit()
|
||||
if await session.commit() is None: # 判断提交结果
|
||||
print("更新机器人状态成功")
|
||||
else:
|
||||
print("更新机器人状态未生效")
|
||||
except Exception as e:
|
||||
print(f"更新机器人在线状态失败: {e}")
|
||||
|
||||
|
||||
@ -26,6 +26,9 @@ class WebSocketClient:
|
||||
user_id = f"{self.ws_config.get('account')}_{timestamp}_{self.ws_config.get('tenantInfoId')}"
|
||||
return f"wss://{self.ws_config.get('url')}{user_id}"
|
||||
|
||||
# 测试用websocket地址
|
||||
# return "ws://10.0.0.202:8788"
|
||||
|
||||
async def save_message(self, message: str):
|
||||
"""保存接收到的消息到文件"""
|
||||
# 获取当前日期作为文件名
|
||||
@ -69,7 +72,7 @@ class WebSocketClient:
|
||||
"""处理接收到的消息"""
|
||||
try:
|
||||
# 保存消息
|
||||
await self.save_message(message)
|
||||
# await self.save_message(message)
|
||||
|
||||
# 尝试解析JSON消息
|
||||
message_dict = json.loads(message)
|
||||
@ -82,7 +85,7 @@ class WebSocketClient:
|
||||
|
||||
# 机器人状态消息
|
||||
elif self._process_robot_status(message_dict):
|
||||
# print("处理机器人状态消息...")
|
||||
print("处理机器人状态消息...")
|
||||
# print(f"{datetime.now()}收到消息: {message}") # 只打印前100个字符
|
||||
await self.event_sync_service.sync_robot_status(message_dict)
|
||||
|
||||
|
||||
@ -49,3 +49,5 @@
|
||||
|
||||
- 修改 requirement.txt文件,删除不必要的头文件, 修改数据库配置.
|
||||
- 更新 更新paddleocr模型
|
||||
- 修改 run_websocket中同步机器人状态逻辑.
|
||||
- 添加 测试用websocket地址
|
||||
|
||||
@ -1 +0,0 @@
|
||||
433729
|
||||
@ -18,3 +18,5 @@ nohup python run_sync_robot.py > "$LOG_FILE" 2>&1 &
|
||||
|
||||
# 保存进程id
|
||||
echo $! > "$LOG_DIR/robot.pid"
|
||||
echo "WebSocket客户端已启动,日志保存在: $LOG_FILE"
|
||||
echo "进程ID: $(cat $LOG_DIR/robot.pid)"
|
||||
Loading…
Reference in New Issue
Block a user