feat: opt exec log

This commit is contained in:
engigu
2026-01-01 14:42:33 +08:00
parent 4dfd45ec69
commit 756ba1e0ea
9 changed files with 115 additions and 30 deletions
+10 -2
View File
@@ -215,7 +215,10 @@ func (a *Agent) closeWS() {
}
func (a *Agent) readWS() {
defer a.closeWS() // 读取结束时关闭连接,停止 heartbeatLoop
defer func() {
log.Info("readWS 退出,准备关闭连接")
a.closeWS()
}()
for {
a.wsMu.Lock()
@@ -223,6 +226,7 @@ func (a *Agent) readWS() {
a.wsMu.Unlock()
if conn == nil {
log.Warn("readWS: wsConn 为 nil")
return
}
@@ -329,7 +333,11 @@ func (a *Agent) sendWSMessage(msgType string, data interface{}) error {
msgBytes, _ := json.Marshal(msg)
a.wsConn.SetWriteDeadline(time.Now().Add(10 * time.Second))
return a.wsConn.WriteMessage(websocket.TextMessage, msgBytes)
if err := a.wsConn.WriteMessage(websocket.TextMessage, msgBytes); err != nil {
log.Warnf("发送消息失败 (%s): %v", msgType, err)
return err
}
return nil
}
func (a *Agent) heartbeatLoop() {