fix: delete id in response

This commit is contained in:
2026-05-14 16:27:59 +03:00
parent 6046b8ae9d
commit b7893603ea
3 changed files with 10 additions and 13 deletions
+3 -5
View File
@@ -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
@@ -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
}
}
@@ -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,