功能:area_id 全链路支持 + 截图处理器独立 Redis 连接
- CameraInfo 模型添加 area_id 字段 - SQLite 表增加 area_id 列及迁移 - config_sync 同步 area_id 到本地 - 告警 ext_data 携带 area_id - 截图处理器使用独立 Redis 连接,避免与配置同步阻塞冲突 - get_all_camera_configs 使用 cursor.description 动态获取列名 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
52
main.py
52
main.py
@@ -185,29 +185,27 @@ class EdgeInferenceService:
|
||||
def _init_screenshot_handler(self):
|
||||
"""初始化截图处理器"""
|
||||
try:
|
||||
# 优先从 config_manager 获取已有的云端 Redis 连接
|
||||
cloud_redis = getattr(self._config_manager, '_cloud_redis', None)
|
||||
|
||||
# LOCAL 模式下 config_manager 不初始化云端 Redis,需要独立创建
|
||||
if cloud_redis is None:
|
||||
try:
|
||||
import redis
|
||||
cfg = self._settings.cloud_redis
|
||||
cloud_redis = redis.Redis(
|
||||
host=cfg.host,
|
||||
port=cfg.port,
|
||||
db=cfg.db,
|
||||
password=cfg.password,
|
||||
decode_responses=cfg.decode_responses,
|
||||
socket_connect_timeout=5,
|
||||
socket_timeout=5,
|
||||
retry_on_timeout=True,
|
||||
)
|
||||
cloud_redis.ping()
|
||||
self._logger.info(f"截图处理器独立连接云端 Redis 成功: {cfg.host}:{cfg.port}/{cfg.db}")
|
||||
except Exception as e:
|
||||
self._logger.warning(f"截图处理器无法连接云端 Redis: {e}")
|
||||
cloud_redis = None
|
||||
# 截图处理器必须使用独立的 Redis 连接(不能与 config_sync 共用,
|
||||
# 因为两者都做阻塞 XREAD/XREADGROUP,共用连接会互相干扰)
|
||||
cloud_redis = None
|
||||
try:
|
||||
import redis
|
||||
cfg = self._settings.cloud_redis
|
||||
cloud_redis = redis.Redis(
|
||||
host=cfg.host,
|
||||
port=cfg.port,
|
||||
db=cfg.db,
|
||||
password=cfg.password,
|
||||
decode_responses=cfg.decode_responses,
|
||||
socket_connect_timeout=5,
|
||||
socket_timeout=10,
|
||||
retry_on_timeout=True,
|
||||
)
|
||||
cloud_redis.ping()
|
||||
self._logger.info(f"截图处理器独立连接云端 Redis 成功: {cfg.host}:{cfg.port}/{cfg.db}")
|
||||
except Exception as e:
|
||||
self._logger.warning(f"截图处理器无法连接云端 Redis: {e}")
|
||||
cloud_redis = None
|
||||
|
||||
if cloud_redis and self._stream_manager:
|
||||
self._screenshot_handler = ScreenshotHandler(
|
||||
@@ -363,7 +361,12 @@ class EdgeInferenceService:
|
||||
)
|
||||
|
||||
self._logger.info("所有组件初始化完成")
|
||||
|
||||
|
||||
def _get_camera_area_id(self, camera_id: str) -> Optional[int]:
|
||||
"""获取摄像头的 area_id"""
|
||||
cam = self._get_camera_config_by_id(camera_id)
|
||||
return cam.area_id if cam else None
|
||||
|
||||
def _get_camera_ids_with_roi(self) -> set:
|
||||
"""获取有ROI配置的摄像头ID集合
|
||||
|
||||
@@ -844,6 +847,7 @@ class EdgeInferenceService:
|
||||
"edge_node_id": self._settings.mqtt.device_id,
|
||||
"first_frame_time": first_frame_time,
|
||||
"vehicle_count": alert.get("vehicle_count"),
|
||||
"area_id": self._get_camera_area_id(camera_id),
|
||||
},
|
||||
)
|
||||
self._reporter.report_alarm(alarm_info, screenshot=frame.image)
|
||||
|
||||
Reference in New Issue
Block a user