Skip to content

Commit

Permalink
Update durabletask-js (#633)
Browse files Browse the repository at this point in the history
* update durabletask-js

Signed-off-by: yaron2 <schneider.yaron@live.com>

* update sha

Signed-off-by: yaron2 <schneider.yaron@live.com>

* adapt durabletask clients initialization

---------

Signed-off-by: yaron2 <schneider.yaron@live.com>
Co-authored-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
  • Loading branch information
yaron2 and famarting authored Sep 19, 2024
1 parent 4c05477 commit 76866c8
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions examples/workflow/authoring/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/workflow/management/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"@grpc/grpc-js": "^1.9.3",
"@js-temporal/polyfill": "^0.3.0",
"@microsoft/durabletask-js": "^0.1.0-alpha.1",
"@microsoft/durabletask-js": "^0.1.0-alpha.2",
"@types/google-protobuf": "^3.15.5",
"@types/node-fetch": "^2.6.2",
"body-parser": "^1.19.0",
Expand Down
7 changes: 4 additions & 3 deletions src/workflow/client/DaprWorkflowClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { generateApiTokenClientInterceptors, generateEndpoint, getDaprApiToken }
import { TWorkflow } from "../../types/workflow/Workflow.type";
import { getFunctionName } from "../internal";
import { WorkflowClientOptions } from "../../types/workflow/WorkflowClientOption";
import { GrpcEndpoint } from "../../network/GrpcEndpoint";

/**
* Class that defines client operations for managing workflow instances.
Expand All @@ -34,18 +35,18 @@ export default class DaprWorkflowClient {
constructor(options: Partial<WorkflowClientOptions> = {}) {
const grpcEndpoint = generateEndpoint(options);
options.daprApiToken = getDaprApiToken(options);
this._innerClient = this.buildInnerClient(grpcEndpoint.endpoint, options);
this._innerClient = this.buildInnerClient(grpcEndpoint, options);
}

private buildInnerClient(hostAddress: string, options: Partial<WorkflowClientOptions>): TaskHubGrpcClient {
private buildInnerClient(grpcEndpoint: GrpcEndpoint, options: Partial<WorkflowClientOptions>): TaskHubGrpcClient {
let innerOptions = options?.grpcOptions;
if (options.daprApiToken !== undefined && options.daprApiToken !== "") {
innerOptions = {
...innerOptions,
interceptors: [generateApiTokenClientInterceptors(options), ...(innerOptions?.interceptors ?? [])],
};
}
return new TaskHubGrpcClient(hostAddress, innerOptions);
return new TaskHubGrpcClient(grpcEndpoint.endpoint, innerOptions, grpcEndpoint.tls);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/workflow/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ export function getFunctionName(fn: TWorkflow | TWorkflowActivity<TInput, TOutpu
* @returns A GrpcEndpoint representing the Dapr gRPC endpoint.
*/
export function generateEndpoint(options: Partial<WorkflowClientOptions>): GrpcEndpoint {
// NOTE: same logic as src/implementation/Client/GRPCClient/GRPCClient.ts
const host = options?.daprHost ?? Settings.getDefaultHost();
const port = options?.daprPort ?? Settings.getDefaultGrpcPort();
const uri = `${host}:${port}`;
let uri = `${host}:${port}`;

if (!(options?.daprHost || options?.daprPort)) {
// If neither host nor port are specified, check the endpoint environment variable.
const endpoint = Settings.getDefaultGrpcEndpoint();
if (endpoint != "") {
uri = endpoint;
}
}

return new GrpcEndpoint(uri);
}

Expand Down
7 changes: 4 additions & 3 deletions src/workflow/runtime/WorkflowRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import WorkflowContext from "./WorkflowContext";
import { generateApiTokenClientInterceptors, generateEndpoint, getDaprApiToken } from "../internal/index";
import { getFunctionName } from "../internal";
import { WorkflowClientOptions } from "../../types/workflow/WorkflowClientOption";
import { GrpcEndpoint } from "../../network/GrpcEndpoint";

/**
* Contains methods to register workflows and activities.
Expand All @@ -34,18 +35,18 @@ export default class WorkflowRuntime {
constructor(options: Partial<WorkflowClientOptions> = {}) {
const grpcEndpoint = generateEndpoint(options);
options.daprApiToken = getDaprApiToken(options);
this.worker = this.buildInnerWorker(grpcEndpoint.endpoint, options);
this.worker = this.buildInnerWorker(grpcEndpoint, options);
}

private buildInnerWorker(hostAddress: string, options: Partial<WorkflowClientOptions>): TaskHubGrpcWorker {
private buildInnerWorker(grpcEndpoint: GrpcEndpoint, options: Partial<WorkflowClientOptions>): TaskHubGrpcWorker {
let innerOptions = options?.grpcOptions;
if (options.daprApiToken !== undefined && options.daprApiToken !== "") {
innerOptions = {
...innerOptions,
interceptors: [generateApiTokenClientInterceptors(options), ...(innerOptions?.interceptors ?? [])],
};
}
return new TaskHubGrpcWorker(hostAddress, innerOptions);
return new TaskHubGrpcWorker(grpcEndpoint.endpoint, innerOptions, grpcEndpoint.tls);
}

/**
Expand Down

0 comments on commit 76866c8

Please sign in to comment.