增加启动时清理redis中错误zlm数据

This commit is contained in:
648540858 2022-10-19 16:25:38 +08:00
parent 6dbc7a68bd
commit 95d367702a
2 changed files with 10 additions and 1 deletions

View File

@ -298,6 +298,7 @@ public class XmlUtil {
}else { }else {
deviceChannel.setParentId(parentId); deviceChannel.setParentId(parentId);
} }
// 兼容设备通道信息中自己为自己父节点的情况
if (deviceChannel.getParentId().equals(deviceChannel.getChannelId())) { if (deviceChannel.getParentId().equals(deviceChannel.getChannelId())) {
deviceChannel.setParentId(null); deviceChannel.setParentId(null);
} }

View File

@ -80,6 +80,7 @@ public class ZLMRunner implements CommandLineRunner {
// 获取所有的zlm 并开启主动连接 // 获取所有的zlm 并开启主动连接
List<MediaServerItem> all = mediaServerService.getAllFromDatabase(); List<MediaServerItem> all = mediaServerService.getAllFromDatabase();
Map<String, MediaServerItem> allMap = new HashMap<>();
mediaServerService.updateVmServer(all); mediaServerService.updateVmServer(all);
if (all.size() == 0) { if (all.size() == 0) {
all.add(mediaConfig.getMediaSerItem()); all.add(mediaConfig.getMediaSerItem());
@ -90,6 +91,7 @@ public class ZLMRunner implements CommandLineRunner {
} }
startGetMedia.put(mediaServerItem.getId(), true); startGetMedia.put(mediaServerItem.getId(), true);
connectZlmServer(mediaServerItem); connectZlmServer(mediaServerItem);
allMap.put(mediaServerItem.getId(), mediaServerItem);
} }
String taskKey = "zlm-connect-timeout"; String taskKey = "zlm-connect-timeout";
dynamicTask.startDelay(taskKey, ()->{ dynamicTask.startDelay(taskKey, ()->{
@ -100,7 +102,13 @@ public class ZLMRunner implements CommandLineRunner {
} }
startGetMedia = null; startGetMedia = null;
} }
// TODO 清理数据库中与redis不匹配的zlm // 获取redis中所有的zlm
List<MediaServerItem> allInRedis = mediaServerService.getAll();
for (MediaServerItem mediaServerItem : allInRedis) {
if (!allMap.containsKey(mediaServerItem.getId())) {
mediaServerService.delete(mediaServerItem.getId());
}
}
}, 60 * 1000 ); }, 60 * 1000 );
} }