-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
cancelPendingCommands.go
34 lines (30 loc) · 1.1 KB
/
cancelPendingCommands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package service
import (
"context"
"github.com/plgd-dev/hub/v2/grpc-gateway/pb"
"github.com/plgd-dev/hub/v2/pkg/log"
kitNetGrpc "github.com/plgd-dev/hub/v2/pkg/net/grpc"
"github.com/plgd-dev/hub/v2/resource-aggregate/commands"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/peer"
)
func (r *RequestHandler) CancelPendingCommands(ctx context.Context, req *pb.CancelPendingCommandsRequest) (*pb.CancelPendingCommandsResponse, error) {
connectionID := ""
peer, ok := peer.FromContext(ctx)
if ok {
connectionID = peer.Addr.String()
}
resp, err := r.resourceAggregateClient.CancelPendingCommands(ctx, &commands.CancelPendingCommandsRequest{
ResourceId: req.GetResourceId(),
CorrelationIdFilter: req.GetCorrelationIdFilter(),
CommandMetadata: &commands.CommandMetadata{
ConnectionId: connectionID,
},
})
if err != nil {
return nil, log.LogAndReturnError(kitNetGrpc.ForwardErrorf(codes.InvalidArgument, "cannot cancel resource('%v') commands: %v", req.GetResourceId().ToString(), err))
}
return &pb.CancelPendingCommandsResponse{
CorrelationIds: resp.GetCorrelationIds(),
}, nil
}