From b7893603ea8e97468db7a5d48cdfed880364ff6e Mon Sep 17 00:00:00 2001 From: lorsan Date: Thu, 14 May 2026 16:27:59 +0300 Subject: [PATCH] fix: delete id in response --- hub/internal/domain/stream.go | 8 +++----- hub/internal/service/connection_manager/agent.go | 10 +++++----- hub/internal/service/connection_manager/mapper.go | 5 ++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/hub/internal/domain/stream.go b/hub/internal/domain/stream.go index 7165398..8870ae4 100644 --- a/hub/internal/domain/stream.go +++ b/hub/internal/domain/stream.go @@ -3,14 +3,12 @@ package domain import "time" type AgentRequest struct { - RequestID string - Name string - Args map[string]string - TimeOut int + Name string + Args map[string]string + TimeOut int } type AgentResponse struct { - RequestID string Success bool Output string Error string diff --git a/hub/internal/service/connection_manager/agent.go b/hub/internal/service/connection_manager/agent.go index c205849..47cfcdf 100644 --- a/hub/internal/service/connection_manager/agent.go +++ b/hub/internal/service/connection_manager/agent.go @@ -68,12 +68,12 @@ func (a *AgentConnection) Listen() error { heartbeat := toCreateHeartbeatModel(a.AgentID, x) heartbeatsChan <- heartbeat case *pb.AgentEvent_CommandResponse: - response := toAgentResponse(x) - ch, ok := a.response.Read(response.RequestID) + ch, ok := a.response.Read(x.CommandResponse.RequestId) if !ok { - a.log.Warn().Str("requestID", response.RequestID).Msg("not found channel for send response") + a.log.Warn().Str("requestID", x.CommandResponse.RequestId).Msg("not found channel for send response") continue } + response := toAgentResponse(x) ch <- response } } @@ -124,7 +124,7 @@ func (a *AgentConnection) Execute(ctx context.Context, request domainHub.AgentRe a.response.Write(requestID, ch) defer a.response.Delete(requestID) - err := a.stream.Send(new(toGRPCCommandRequest(request))) + err := a.stream.Send(new(toGRPCCommandRequest(requestID, request))) if err != nil { return domainHub.AgentResponse{}, fmt.Errorf("execute command: %w", err) } @@ -137,7 +137,7 @@ func (a *AgentConnection) Execute(ctx context.Context, request domainHub.AgentRe case <-ctx.Done(): return domainHub.AgentResponse{}, fmt.Errorf("request timeout") case response := <-ch: - a.log.Info().Str("requestID", response.RequestID).Msg("received response") + a.log.Info().Str("requestID", requestID).Msg("received response") return response, nil } } diff --git a/hub/internal/service/connection_manager/mapper.go b/hub/internal/service/connection_manager/mapper.go index 12783e0..68fa0ac 100644 --- a/hub/internal/service/connection_manager/mapper.go +++ b/hub/internal/service/connection_manager/mapper.go @@ -21,9 +21,9 @@ func toCreateHeartbeatModel(agentID string, heartbeat *pb.AgentEvent_Heartbeat) } } -func toGRPCCommandRequest(request domainHub.AgentRequest) pb.ServerCommandRequest { +func toGRPCCommandRequest(requestID string, request domainHub.AgentRequest) pb.ServerCommandRequest { return pb.ServerCommandRequest{ - RequestId: request.RequestID, + RequestId: requestID, Name: request.Name, TimeoutSeconds: int64(request.TimeOut), Args: request.Args, @@ -32,7 +32,6 @@ func toGRPCCommandRequest(request domainHub.AgentRequest) pb.ServerCommandReques func toAgentResponse(response *pb.AgentEvent_CommandResponse) domainHub.AgentResponse { return domainHub.AgentResponse{ - RequestID: response.CommandResponse.RequestId, Success: response.CommandResponse.Success, Error: response.CommandResponse.Error, Output: response.CommandResponse.Output,