Browse Source

新增日志

xyxie 3 days ago
parent
commit
d2ea3cb212
1 changed files with 15 additions and 2 deletions
  1. 15 2
      services/websocket_msg.go

+ 15 - 2
services/websocket_msg.go

@@ -44,6 +44,7 @@ func DealEdbInspectionMessage(conn *websocket.Conn, adminId int) {
 
 	// 设置连接关闭处理器
 	conn.SetCloseHandler(func(code int, text string) error {
+		utils.FileLog.Info("长连接关闭, adminId:%d", adminId)
 		cancel()
 		return nil
 	})
@@ -64,12 +65,17 @@ func DealEdbInspectionMessage(conn *websocket.Conn, adminId int) {
 		default:
 			// 使用带超时的 Redis 操作
 			err := utils.Rc.BrpopWithTimeout(cacheKey, 30*time.Second, func(b []byte) {
-				messageList, err := data.GetHistoryInspectionMessages(adminId)
+				utils.FileLog.Info("收到巡检信息开始处理, adminId:%d", adminId)
 
+				messageList, err := data.GetHistoryInspectionMessages(adminId)
 				if err != nil {
 					utils.FileLog.Error("获取巡检信息历史失败,err:%s, adminId:%d", err.Error(), adminId)
 					return
 				}
+				if len(messageList) == 0 {
+					utils.FileLog.Info("巡检信息历史为空, adminId:%d", adminId)
+					return
+				}
 				readList := make([]int64, 0)
 				// 消息发送 goroutine
 
@@ -93,6 +99,11 @@ func DealEdbInspectionMessage(conn *websocket.Conn, adminId int) {
 							// 使用互斥锁保护 WebSocket 写操作
 							wsWriteMutex.Lock()
 							err = conn.WriteJSON(resp)
+							if err != nil {
+								utils.FileLog.Error("巡检信息写通道被锁,消息发送失败,err:%s, adminId:%d", err.Error(), adminId)
+								wsWriteMutex.Unlock()
+								continue
+							}
 							wsWriteMutex.Unlock()
 
 							if err != nil {
@@ -118,7 +129,9 @@ func DealEdbInspectionMessage(conn *websocket.Conn, adminId int) {
 
 			if err != nil {
 				utils.FileLog.Error("Redis operation failed: %v", err)
-				return
+				continue
+			}else{
+				utils.FileLog.Info("巡检信息处理完成, adminId:%d", adminId)
 			}
 		}
 	}