Skip to content

Commit 57f4675

Browse files
Merge pull request #157 from XavierGeerinck/api-shutdown
feat: Add shutdown API
2 parents d21261c + e0fce66 commit 57f4675

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Version 2.0.0 brings a lot of changes to the Dapr JS SDK that were long due. Bel
1111
* The HTTP Connection is now being reused to reduce the CONNRESET errors when intensively using the JS SDK
1212
* The [Metadata API](https://docs.dapr.io/reference/api/metadata_api/) is supported
1313
* The [Health API](https://docs.dapr.io/reference/api/health_api/) is supported
14+
* The `/v1.0/shutdown` [API endpoint](https://docs.dapr.io/operations/hosting/kubernetes/kubernetes-job/) is now supported by calling `await client.sidecar.shutdown()`
1415

1516
#### Breaking Changes
1617

@@ -23,5 +24,6 @@ Version 2.0.0 brings a lot of changes to the Dapr JS SDK that were long due. Bel
2324
* `healthz` endpoint was implemented as `client.health.isHealthy()` for gRPC this checks the `getMetadata` function since it does not have a Health PROTO.
2425
* Server startup now ensures the Dapr Sidecar is healthy before starting
2526
* Add metadata API for gRPC and HTTP
27+
* Add the SDK implementation for gRPC and HTTP for shutting down the Sidecar through the SDK
2628

2729
## 1.x release

src/implementation/Client/DaprClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import IClientInvoker from '../../interfaces/Client/IClientInvoker';
55
import IClientSecret from '../../interfaces/Client/IClientSecret';
66
import IClientHealth from '../../interfaces/Client/IClientHealth';
77
import IClientMetadata from '../../interfaces/Client/IClientMetadata';
8+
import IClientSidecar from '../../interfaces/Client/IClientSidecar';
89
import IClient from '../../interfaces/Client/IClient';
910

1011
import GRPCClientBinding from './GRPCClient/binding';
@@ -14,6 +15,7 @@ import GRPCClientInvoker from './GRPCClient/invoker';
1415
import GRPCClientSecret from './GRPCClient/secret';
1516
import GRPCClientHealth from './GRPCClient/health';
1617
import GRPCClientMetadata from './GRPCClient/metadata';
18+
import GRPCClientSidecar from './GRPCClient/sidecar';
1719
import GRPCClient from './GRPCClient/GRPCClient';
1820

1921
import HTTPClientBinding from './HTTPClient/binding';
@@ -23,6 +25,7 @@ import HTTPClientInvoker from './HTTPClient/invoker';
2325
import HTTPClientSecret from './HTTPClient/secret';
2426
import HTTPClientHealth from './HTTPClient/health';
2527
import HTTPClientMetadata from './HTTPClient/metadata';
28+
import HTTPClientSidecar from './HTTPClient/sidecar';
2629
import HTTPClient from './HTTPClient/HTTPClient';
2730

2831
import CommunicationProtocolEnum from '../../enum/CommunicationProtocol.enum';
@@ -42,6 +45,7 @@ export default class DaprClient {
4245
readonly secret: IClientSecret;
4346
readonly health: IClientHealth;
4447
readonly metadata: IClientMetadata;
48+
readonly sidecar: IClientSidecar;
4549

4650
constructor(
4751
daprHost: string
@@ -74,6 +78,7 @@ export default class DaprClient {
7478
this.secret = new GRPCClientSecret(client);
7579
this.health = new GRPCClientHealth(client);
7680
this.metadata = new GRPCClientMetadata(client);
81+
this.sidecar = new GRPCClientSidecar(client);
7782
break;
7883
}
7984
case CommunicationProtocolEnum.HTTP:
@@ -88,6 +93,7 @@ export default class DaprClient {
8893
this.secret = new HTTPClientSecret(client);
8994
this.health = new HTTPClientHealth(client);
9095
this.metadata = new HTTPClientMetadata(client);
96+
this.sidecar = new HTTPClientSidecar(client);
9197
break;
9298
}
9399
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import GRPCClient from './GRPCClient';
2+
import IClientSidecar from "../../../interfaces/Client/IClientSidecar";
3+
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
4+
5+
// https://docs.dapr.io/reference/api/secrets_api/
6+
export default class GRPCClientSidecar implements IClientSidecar {
7+
client: GRPCClient;
8+
9+
constructor(client: GRPCClient) {
10+
this.client = client;
11+
}
12+
13+
async shutdown(): Promise<void> {
14+
return new Promise((resolve, reject) => {
15+
const client = this.client.getClient();
16+
client.shutdown(new Empty(), (err, res: Empty) => {
17+
if (err) {
18+
return reject(err);
19+
}
20+
21+
return resolve();
22+
});
23+
});
24+
}
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import HTTPClient from './HTTPClient';
2+
import IClientSidecar from '../../../interfaces/Client/IClientSidecar';
3+
4+
// https://docs.dapr.io/reference/api/bindings_api/
5+
export default class HTTPClientSidecar implements IClientSidecar {
6+
client: HTTPClient;
7+
8+
constructor(client: HTTPClient) {
9+
this.client = client;
10+
}
11+
12+
async shutdown(): Promise<void> {
13+
await this.client.execute(`/shutdown`, {
14+
method: 'POST'
15+
});
16+
}
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default interface IClientSidecar {
2+
shutdown(): Promise<void>;
3+
}

0 commit comments

Comments
 (0)