Skip to content

Commit 562562a

Browse files
authored
feat: add shutdown api (#151)
1 parent 7a89cf3 commit 562562a

File tree

4 files changed

+102
-31
lines changed

4 files changed

+102
-31
lines changed

client/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/pkg/errors"
1111
"google.golang.org/grpc"
1212
"google.golang.org/grpc/metadata"
13+
"google.golang.org/protobuf/types/known/emptypb"
1314

1415
pb "github.com/dapr/go-sdk/dapr/proto/runtime/v1"
1516
)
@@ -90,6 +91,9 @@ type Client interface {
9091
// DeleteBulkState deletes content for multiple keys from store.
9192
DeleteBulkStateItems(ctx context.Context, storeName string, items []*DeleteStateItem) error
9293

94+
// Shutdown the sidecar.
95+
Shutdown(ctx context.Context) error
96+
9397
// WithTraceID adds existing trace ID to the outgoing context.
9498
WithTraceID(ctx context.Context, id string) context.Context
9599

@@ -194,3 +198,12 @@ func (c *GRPCClient) withAuthToken(ctx context.Context) context.Context {
194198
}
195199
return metadata.NewOutgoingContext(ctx, metadata.Pairs(apiTokenKey, string(c.authToken)))
196200
}
201+
202+
// Shutdown the sidecar.
203+
func (c *GRPCClient) Shutdown(ctx context.Context) error {
204+
_, err := c.protoClient.Shutdown(c.withAuthToken(ctx), &emptypb.Empty{})
205+
if err != nil {
206+
return errors.Wrap(err, "error shutting down the sidecar")
207+
}
208+
return nil
209+
}

client/client_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ func TestNewClient(t *testing.T) {
6363
})
6464
}
6565

66+
func TestShutdown(t *testing.T) {
67+
ctx := context.Background()
68+
69+
t.Run("shutdown", func(t *testing.T) {
70+
err := testClient.Shutdown(ctx)
71+
assert.NoError(t, err)
72+
})
73+
}
74+
75+
6676
func getTestClient(ctx context.Context) (client Client, closer func()) {
6777
s := grpc.NewServer()
6878
pb.RegisterDaprServer(s, &testDaprServer{
@@ -220,3 +230,7 @@ func (s *testDaprServer) RegisterActorTimer(context.Context, *pb.RegisterActorTi
220230
func (s *testDaprServer) UnregisterActorTimer(context.Context, *pb.UnregisterActorTimerRequest) (*empty.Empty, error) {
221231
return nil, errors.New("actors not implemented in go SDK")
222232
}
233+
234+
func (s *testDaprServer) Shutdown(ctx context.Context, req *empty.Empty) (*empty.Empty, error) {
235+
return &empty.Empty{}, nil
236+
}

dapr/proto/runtime/v1/dapr.pb.go

Lines changed: 37 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dapr/proto/runtime/v1/dapr_grpc.pb.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)