mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 16:45:15 +03:00
fix: delete id in response
This commit is contained in:
@@ -3,14 +3,12 @@ package domain
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type AgentRequest struct {
|
type AgentRequest struct {
|
||||||
RequestID string
|
Name string
|
||||||
Name string
|
Args map[string]string
|
||||||
Args map[string]string
|
TimeOut int
|
||||||
TimeOut int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AgentResponse struct {
|
type AgentResponse struct {
|
||||||
RequestID string
|
|
||||||
Success bool
|
Success bool
|
||||||
Output string
|
Output string
|
||||||
Error string
|
Error string
|
||||||
|
|||||||
@@ -68,12 +68,12 @@ func (a *AgentConnection) Listen() error {
|
|||||||
heartbeat := toCreateHeartbeatModel(a.AgentID, x)
|
heartbeat := toCreateHeartbeatModel(a.AgentID, x)
|
||||||
heartbeatsChan <- heartbeat
|
heartbeatsChan <- heartbeat
|
||||||
case *pb.AgentEvent_CommandResponse:
|
case *pb.AgentEvent_CommandResponse:
|
||||||
response := toAgentResponse(x)
|
ch, ok := a.response.Read(x.CommandResponse.RequestId)
|
||||||
ch, ok := a.response.Read(response.RequestID)
|
|
||||||
if !ok {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
response := toAgentResponse(x)
|
||||||
ch <- response
|
ch <- response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ func (a *AgentConnection) Execute(ctx context.Context, request domainHub.AgentRe
|
|||||||
a.response.Write(requestID, ch)
|
a.response.Write(requestID, ch)
|
||||||
defer a.response.Delete(requestID)
|
defer a.response.Delete(requestID)
|
||||||
|
|
||||||
err := a.stream.Send(new(toGRPCCommandRequest(request)))
|
err := a.stream.Send(new(toGRPCCommandRequest(requestID, request)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domainHub.AgentResponse{}, fmt.Errorf("execute command: %w", err)
|
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():
|
case <-ctx.Done():
|
||||||
return domainHub.AgentResponse{}, fmt.Errorf("request timeout")
|
return domainHub.AgentResponse{}, fmt.Errorf("request timeout")
|
||||||
case response := <-ch:
|
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
|
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{
|
return pb.ServerCommandRequest{
|
||||||
RequestId: request.RequestID,
|
RequestId: requestID,
|
||||||
Name: request.Name,
|
Name: request.Name,
|
||||||
TimeoutSeconds: int64(request.TimeOut),
|
TimeoutSeconds: int64(request.TimeOut),
|
||||||
Args: request.Args,
|
Args: request.Args,
|
||||||
@@ -32,7 +32,6 @@ func toGRPCCommandRequest(request domainHub.AgentRequest) pb.ServerCommandReques
|
|||||||
|
|
||||||
func toAgentResponse(response *pb.AgentEvent_CommandResponse) domainHub.AgentResponse {
|
func toAgentResponse(response *pb.AgentEvent_CommandResponse) domainHub.AgentResponse {
|
||||||
return domainHub.AgentResponse{
|
return domainHub.AgentResponse{
|
||||||
RequestID: response.CommandResponse.RequestId,
|
|
||||||
Success: response.CommandResponse.Success,
|
Success: response.CommandResponse.Success,
|
||||||
Error: response.CommandResponse.Error,
|
Error: response.CommandResponse.Error,
|
||||||
Output: response.CommandResponse.Output,
|
Output: response.CommandResponse.Output,
|
||||||
|
|||||||
Reference in New Issue
Block a user