修改--修改数据库同步脚本

This commit is contained in:
haotian 2025-06-17 14:49:33 +08:00
parent d45321ab6f
commit ab8be824be
5 changed files with 14 additions and 7 deletions

View File

@ -13,7 +13,7 @@ class Settings(BaseSettings):
# DB_NAME: str = "kangda_test" # 测试数据库
DB_CHARSET: str = "utf8mb4"
DB_POOL_SIZE: int = 5
DB_POOL_SIZE: int = 10
DB_MAX_OVERFLOW: int = 10
DB_POOL_TIMEOUT: int = 30
DB_POOL_RECYCLE: int = 1800

View File

@ -4,6 +4,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select, update
from app.models.models import Robot, RobotInfo, Group, GroupRobot, Task
from app.util.kangda import Kangda
from datetime import datetime
# from app.core.redis import redis_client
class RobotSyncService:
@ -27,10 +28,10 @@ class RobotSyncService:
await self.update_task_database(db, task_list)
print("同步机器人任务完成")
print(datetime.now(),"同步机器人任务完成")
except Exception as e:
print(f"同步机器人数据失败: {str(e)}")
print(f"{datetime.now()} 同步机器人数据失败: {str(e)}")
await db.rollback()
return False
@ -45,6 +46,7 @@ class RobotSyncService:
if not t:
t = Task()
# t.updateTime
db.add(t)
# 更新字段
for k, v in task.items():
@ -54,7 +56,7 @@ class RobotSyncService:
await db.flush()
await db.commit()
except Exception as e:
print("更新机器人任务出错", e)
print(datetime.now(),"更新机器人任务出错", e)
db.rollback()
return False
@ -90,7 +92,7 @@ class RobotSyncService:
return True
except Exception as e:
print(f"同步机器人数据失败: {str(e)}")
print(f"{datetime.now()}同步机器人数据失败: {str(e)}")
await db.rollback()
return False
@ -156,6 +158,7 @@ class RobotSyncService:
robot_info = RobotInfo(robotId=robot_id)
db.add(robot_info)
robot_info.updateTime = datetime.now()
# 更新字段
for key, value in robot_data.items():
if hasattr(robot_info, key):

View File

@ -23,7 +23,7 @@ class Scheduler:
# 同步机器人任务信息
await robot_sync_service.sync_robot_task(session)
# 等待5分钟
# 等待10分钟
await asyncio.sleep(600)
except Exception as e:

View File

@ -144,7 +144,7 @@ class WebSocketClient:
except Exception as e:
self.is_connected = False
print(f"WebSocket连接出错: {str(e)}")
print(f"{datetime.now()} WebSocket连接出错: {str(e)}")
print(f"将在 {self.reconnect_delay} 秒后重试...")
await asyncio.sleep(self.reconnect_delay)

View File

@ -51,3 +51,7 @@
- 更新 更新paddleocr模型
- 修改 run_websocket中同步机器人状态逻辑.
- 添加 测试用websocket地址
# 20250617
- 修改 同步数据库脚本