Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
Signed-off-by: kaibocai <[email protected]>
  • Loading branch information
kaibocai committed Jan 10, 2024
1 parent 378dfe2 commit c3d8d77
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/workflow/authoring/src/activity-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { WorkflowClient, WorkflowActivityContext, WorkflowContext, WorkflowRuntime, TWorkflow } from "@dapr/dapr";
import { DaprWorkflowClient, WorkflowActivityContext, WorkflowContext, WorkflowRuntime, TWorkflow } from "@dapr/dapr";

(async () => {
const grpcEndpoint = "localhost:50001";
const workflowClient = new WorkflowClient(grpcEndpoint);
const workflowClient = new DaprWorkflowClient(grpcEndpoint);
const workflowRuntime = new WorkflowRuntime(grpcEndpoint);

const hello = async (_: WorkflowActivityContext, name: string) => {
Expand Down
11 changes: 9 additions & 2 deletions examples/workflow/authoring/src/fanout-fanin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Task, WorkflowClient, WorkflowActivityContext, WorkflowContext, WorkflowRuntime, TWorkflow } from "@dapr/dapr";
import {
Task,
DaprWorkflowClient,
WorkflowActivityContext,
WorkflowContext,
WorkflowRuntime,
TWorkflow,
} from "@dapr/dapr";

// Wrap the entire code in an immediately-invoked async function
(async () => {
// Update the gRPC client and worker to use a local address and port
const grpcServerAddress = "localhost:50001";
const workflowClient: WorkflowClient = new WorkflowClient(grpcServerAddress);
const workflowClient: DaprWorkflowClient = new DaprWorkflowClient(grpcServerAddress);
const workflowRuntime: WorkflowRuntime = new WorkflowRuntime(grpcServerAddress);

function getRandomInt(min: number, max: number): number {
Expand Down
11 changes: 9 additions & 2 deletions examples/workflow/authoring/src/human-interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Task, WorkflowClient, WorkflowActivityContext, WorkflowContext, WorkflowRuntime, TWorkflow } from "@dapr/dapr";
import {
Task,
DaprWorkflowClient,
WorkflowActivityContext,
WorkflowContext,
WorkflowRuntime,
TWorkflow,
} from "@dapr/dapr";
import * as readlineSync from "readline-sync";

// Wrap the entire code in an immediately-invoked async function
Expand All @@ -33,7 +40,7 @@ import * as readlineSync from "readline-sync";

// Update the gRPC client and worker to use a local address and port
const grpcServerAddress = "localhost:50001";
const workflowClient: WorkflowClient = new WorkflowClient(grpcServerAddress);
const workflowClient: DaprWorkflowClient = new DaprWorkflowClient(grpcServerAddress);
const workflowRuntime: WorkflowRuntime = new WorkflowRuntime(grpcServerAddress);

//Activity function that sends an approval request to the manager
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import StateConcurrencyEnum from "./enum/StateConcurrency.enum";
import StateConsistencyEnum from "./enum/StateConsistency.enum";
import { StateGetBulkOptions } from "./types/state/StateGetBulkOptions.type";

import WorkflowClient from "./workflow/client/WorkflowClient";
import DaprWorkflowClient from "./workflow/client/WorkflowClient";
import WorkflowActivityContext from "./workflow/runtime/WorkflowActivityContext";
import WorkflowContext from "./workflow/runtime/WorkflowContext";
import WorkflowRuntime from "./workflow/runtime/WorkflowRuntime";
Expand Down Expand Up @@ -79,7 +79,7 @@ export {
StateConsistencyEnum,
PubSubBulkPublishResponse,
StateGetBulkOptions,
WorkflowClient,
DaprWorkflowClient,
WorkflowActivityContext,
WorkflowContext,
WorkflowRuntime,
Expand Down
8 changes: 6 additions & 2 deletions src/workflow/client/WorkflowClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { WorkflowState } from "./WorkflowState";
import { generateInterceptors } from "../internal/ApiTokenClientInterceptor";
import { TWorkflow } from "../../types/workflow/Workflow.type";
import { getFunctionName } from "../internal";
import { Settings } from "../../utils/Settings.util";

export default class WorkflowClient {
export default class DaprWorkflowClient {
private readonly _innerClient: TaskHubGrpcClient;

/**
Expand All @@ -30,11 +31,14 @@ export default class WorkflowClient {
this._innerClient = this.buildInnerClient(hostAddress, options);
}

private buildInnerClient(hostAddress = "127.0.0.1:50001", options: grpc.ChannelOptions = {}): TaskHubGrpcClient {
private buildInnerClient(hostAddress?: string, options: grpc.ChannelOptions = {}): TaskHubGrpcClient {
const innerOptions = {
...options,
interceptors: [generateInterceptors(), ...(options?.interceptors ?? [])],
};
if (hostAddress === undefined) {
hostAddress = Settings.getDefaultHost() + ":" + Settings.getDefaultGrpcPort();
}
return new TaskHubGrpcClient(hostAddress, innerOptions);
}

Expand Down
3 changes: 1 addition & 2 deletions src/workflow/runtime/WorkflowContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ limitations under the License.

import { OrchestrationContext } from "@microsoft/durabletask-js";
import { Task } from "@microsoft/durabletask-js/task/task";
import { TInput } from "@microsoft/durabletask-js/types/input.type";
import { TOutput } from "@microsoft/durabletask-js/types/output.type";
import { TWorkflowActivity } from "../../types/workflow/Activity.type";
import { TWorkflow } from "../../types/workflow/Workflow.type";
import { getFunctionName } from "../internal";
import { WhenAllTask } from "@microsoft/durabletask-js/task/when-all-task";
import { whenAll, whenAny } from "@microsoft/durabletask-js/task";
import { WhenAnyTask } from "@microsoft/durabletask-js/task/when-any-task";
import { TInput, TOutput } from "../../types/workflow/InputOutput.type";

export default class WorkflowContext {
private readonly _innerContext: OrchestrationContext;
Expand Down
2 changes: 1 addition & 1 deletion src/workflow/runtime/WorkflowRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class WorkflowRuntime {
/**
* Registers a Workflow implementation for handling orchestrations with a given name.
* The name provided need not be same as workflow name.
*
*
* @param {string} name - The name or identifier for the registered Workflow.
* @param {TWorkflow} workflow - The instance of the Workflow class being registered.
*/
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/workflow/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import WorkflowClient from "../../../src/workflow/client/WorkflowClient";
import DaprWorkflowClient from "../../../src/workflow/client/WorkflowClient";
import WorkflowContext from "../../../src/workflow/runtime/WorkflowContext";
import WorkflowRuntime from "../../../src/workflow/runtime/WorkflowRuntime";
import { TWorkflow } from "../../../src/types/workflow/Workflow.type";
Expand All @@ -22,12 +22,12 @@ import { Task } from "@microsoft/durabletask-js/task/task";

describe("Workflow", () => {
const grpcEndpoint = "localhost:4001";
let workflowClient: WorkflowClient;
let workflowClient: DaprWorkflowClient;
let workflowRuntime: WorkflowRuntime;

beforeEach(async () => {
// Start a worker, which will connect to the sidecar in a background thread
workflowClient = new WorkflowClient(grpcEndpoint);
workflowClient = new DaprWorkflowClient(grpcEndpoint);
workflowRuntime = new WorkflowRuntime(grpcEndpoint);
});

Expand Down

0 comments on commit c3d8d77

Please sign in to comment.