Skip to content

Commit

Permalink
minor updates on comments
Browse files Browse the repository at this point in the history
Signed-off-by: kaibocai <[email protected]>
  • Loading branch information
kaibocai committed Jan 15, 2024
1 parent bb7a01e commit c95ba77
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 46 deletions.
12 changes: 6 additions & 6 deletions examples/workflow/authoring/src/activity-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import { DaprWorkflowClient, WorkflowActivityContext, WorkflowContext, WorkflowR

async function start() {
// Update the gRPC client and worker to use a local address and port
const clientHost = "localhost";
const clientPort = "50001"
const daprHost = "localhost";
const daprPort = "50001";
const workflowClient = new DaprWorkflowClient({
clientHost,
clientPort,
daprHost,
daprPort,
});
const workflowRuntime = new WorkflowRuntime({
clientHost,
clientPort,
daprHost,
daprPort,
});

const hello = async (_: WorkflowActivityContext, name: string) => {
Expand Down
12 changes: 6 additions & 6 deletions examples/workflow/authoring/src/fanout-fanin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import {
// Wrap the entire code in an immediately-invoked async function
async function start() {
// Update the gRPC client and worker to use a local address and port
const clientHost = "localhost";
const clientPort = "50001"
const daprHost = "localhost";
const daprPort = "50001";
const workflowClient = new DaprWorkflowClient({
clientHost,
clientPort,
daprHost,
daprPort,
});
const workflowRuntime = new WorkflowRuntime({
clientHost,
clientPort,
daprHost,
daprPort,
});

function getRandomInt(min: number, max: number): number {
Expand Down
16 changes: 8 additions & 8 deletions examples/workflow/authoring/src/human-interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ async function start() {
}

// Update the gRPC client and worker to use a local address and port
const clientHost = "localhost";
const clientPort = "50001"
const daprHost = "localhost";
const daprPort = "50001";
const workflowClient = new DaprWorkflowClient({
clientHost,
clientPort,
daprHost,
daprPort,
});
const workflowRuntime = new WorkflowRuntime({
clientHost,
clientPort,
daprHost,
daprPort,
});

//Activity function that sends an approval request to the manager
// Activity function that sends an approval request to the manager
const sendApprovalRequest = async (_: WorkflowActivityContext, order: Order) => {
// Simulate some work that takes an amount of time
await sleep(3000);
Expand Down Expand Up @@ -111,7 +111,7 @@ async function start() {
const id = await workflowClient.scheduleNewWorkflow(purchaseOrderWorkflow, order);
console.log(`Orchestration scheduled with ID: ${id}`);

//prompt for approval asynchronously
// prompt for approval asynchronously
promptForApproval(approver, workflowClient, id);

// Wait for orchestration completion
Expand Down
8 changes: 4 additions & 4 deletions src/types/workflow/WorkflowClientOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export type WorkflowClientOptions = {
* Host location of the Dapr sidecar.
* Default is 127.0.0.1.
*/
clientHost: string;
daprHost: string;

/**
* Port of the Dapr sidecar.
* Default is 4001.
* Port of the Dapr sidecar running a gRPC server.
* Default is 50001.
*/
clientPort: string;
daprPort: string;

/**
* Options related to logging.
Expand Down
19 changes: 10 additions & 9 deletions src/workflow/client/DaprWorkflowClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TWorkflow } from "../../types/workflow/Workflow.type";
import { getFunctionName } from "../internal";
import { Settings } from "../../utils/Settings.util";
import { WorkflowClientOptions } from "../../types/workflow/WorkflowClientOption";
import { GrpcEndpoint } from "../../network/GrpcEndpoint";

/**
* Class that defines client operations for managing workflow instances.
Expand All @@ -33,19 +34,19 @@ export default class DaprWorkflowClient {
* @param {WorkflowClientOptions | undefined} options - Additional options for configuring DaprWorkflowClient.
*/
constructor(options: Partial<WorkflowClientOptions> = {}) {
const hostAddress = this.generateHostAddress(options);
options.daprApiToken = this.generateDaprApiToken(options);
this._innerClient = this.buildInnerClient(hostAddress, options);
const grpcEndpoint = this.generateEndpoint(options);
options.daprApiToken = this.getDaprApiToken(options);
this._innerClient = this.buildInnerClient(grpcEndpoint.endpoint, options);
}

private generateHostAddress(options: Partial<WorkflowClientOptions>): string {
const host = options?.clientHost ?? Settings.getDefaultHost();
const port = options?.clientPort ?? Settings.getDefaultGrpcPort();
const hostAddress = `${host}:${port}`;
return hostAddress;
private generateEndpoint(options: Partial<WorkflowClientOptions>): GrpcEndpoint {
const host = options?.daprHost ?? Settings.getDefaultHost();
const port = options?.daprPort ?? Settings.getDefaultGrpcPort();
const uri = `${host}:${port}`;
return new GrpcEndpoint(uri);
}

private generateDaprApiToken(options: Partial<WorkflowClientOptions>): string | undefined {
private getDaprApiToken(options: Partial<WorkflowClientOptions>): string | undefined {
const daprApiToken = options?.daprApiToken ?? Settings.getDefaultApiToken();
return daprApiToken;
}
Expand Down
19 changes: 10 additions & 9 deletions src/workflow/runtime/WorkflowRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { generateApiTokenClientInterceptors } from "../internal/index";
import { getFunctionName } from "../internal";
import { Settings } from "../../utils/Settings.util";
import { WorkflowClientOptions } from "../../types/workflow/WorkflowClientOption";
import { GrpcEndpoint } from "../../network/GrpcEndpoint";

/**
* Contains methods to register workflows and activities.
Expand All @@ -33,19 +34,19 @@ export default class WorkflowRuntime {
* @param {WorkflowClientOptions | undefined} options - Additional options for configuring WorkflowRuntime.
*/
constructor(options: Partial<WorkflowClientOptions> = {}) {
const hostAddress = this.generateHostAddress(options);
options.daprApiToken = this.generateDaprApiToken(options);
this.worker = this.buildInnerWorker(hostAddress, options);
const grpcEndpoint = this.generateEndpoint(options);
options.daprApiToken = this.getDaprApiToken(options);
this.worker = this.buildInnerWorker(grpcEndpoint.endpoint, options);
}

private generateHostAddress(options: Partial<WorkflowClientOptions>): string {
const host = options?.clientHost ?? Settings.getDefaultHost();
const port = options?.clientPort ?? Settings.getDefaultGrpcPort();
const hostAddress = `${host}:${port}`;
return hostAddress;
private generateEndpoint(options: Partial<WorkflowClientOptions>): GrpcEndpoint {
const host = options?.daprHost ?? Settings.getDefaultHost();
const port = options?.daprPort ?? Settings.getDefaultGrpcPort();
const uri = `${host}:${port}`;
return new GrpcEndpoint(uri);
}

private generateDaprApiToken(options: Partial<WorkflowClientOptions>): string | undefined {
private getDaprApiToken(options: Partial<WorkflowClientOptions>): string | undefined {
const daprApiToken = options?.daprApiToken ?? Settings.getDefaultApiToken();
return daprApiToken;
}
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/workflow/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ describe("Workflow", () => {
beforeEach(async () => {
// Start a worker, which will connect to the sidecar in a background thread
workflowClient = new DaprWorkflowClient({
clientHost,
clientPort,
daprHost: clientHost,
daprPort: clientPort,
});
workflowRuntime = new WorkflowRuntime({
clientHost,
clientPort,
daprHost: clientHost,
daprPort: clientPort,
});
});

Expand Down

0 comments on commit c95ba77

Please sign in to comment.