-
Notifications
You must be signed in to change notification settings - Fork 94
Workflow authoring support #563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d1bd43e
init support for workflow
kaibocai 8dd0f6f
add human-interaction example
kaibocai 3a2649f
add test suits for workflow
kaibocai 781a620
minor updates
kaibocai 873bb69
clean up - update durabletask-js dependency
kaibocai 404778a
update to microsoft/durabletask-js - move examples
kaibocai d1619a2
minor updates on examples
kaibocai 378dfe2
minor updates on comments
kaibocai c3d8d77
minor updates
kaibocai cc444db
refactor:update examples - add doc - add unit tests
kaibocai acc0010
mitigate issue from sidecar
kaibocai 59db429
update darpApiToken set strategy
kaibocai bb7a01e
update examples
kaibocai c95ba77
minor updates on comments
kaibocai 41c6785
remove duplications
kaibocai 50b4b7d
add docs
kaibocai 6fb6544
fix warnings - remove unused dependencies
kaibocai fb4ef7f
minor updates
kaibocai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/bin/bash | ||
| # Start the sidecar if it is not running yet | ||
| if [ ! "$(docker ps -q -f name=durabletask-sidecar)" ]; then | ||
| if [ "$(docker ps -aq -f status=exited -f name=durabletask-sidecar)" ]; then | ||
| # cleanup | ||
| docker rm durabletask-sidecar | ||
| fi | ||
|
|
||
| # run your container | ||
| echo "Starting Sidecar" | ||
| docker run \ | ||
| --name durabletask-sidecar -d --rm \ | ||
| -p 4001:4001 \ | ||
| --env 'DURABLETASK_SIDECAR_LOGLEVEL=Debug' \ | ||
| cgillum/durabletask-sidecar:latest start \ | ||
| --backend Emulator | ||
| fi | ||
|
|
||
| echo "Running workflow E2E tests" | ||
| npm run test:e2e:workflow:internal | ||
|
|
||
| # It should fail if the npm run fails | ||
| if [ $? -ne 0 ]; then | ||
| echo "E2E tests failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Stopping Sidecar" | ||
| docker stop durabletask-sidecar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| /* | ||
| Copyright 2022 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { TaskHubGrpcClient } from "kaibocai-durabletask-js"; | ||
| import * as grpc from "@grpc/grpc-js"; | ||
| import { WorkflowState } from "./WorkflowState"; | ||
| import { generateInterceptors } from "../internal/ApiTokenClientInterceptor"; | ||
| import { TWorkflow } from "../types/Workflow.type"; | ||
| import { getFunctionName } from "../internal"; | ||
|
|
||
| export default class WorkflowClient { | ||
kaibocai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private readonly _innerClient: TaskHubGrpcClient; | ||
|
|
||
| /** | ||
| * Initializes a new instance of the DaprWorkflowClient. | ||
| * @param {string | undefined} hostAddress - The address of the Dapr runtime hosting the workflow services. | ||
| * @param {grpc.ChannelOptions | undefined} options - Additional options for configuring the gRPC channel. | ||
| */ | ||
| constructor(hostAddress?: string, options?: grpc.ChannelOptions) { | ||
| this._innerClient = this._buildInnerClient(hostAddress, options); | ||
| } | ||
|
|
||
| _buildInnerClient(hostAddress = "127.0.0.1:50001", options: grpc.ChannelOptions = {}): TaskHubGrpcClient { | ||
kaibocai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const innerOptions = { | ||
| ...options, | ||
| interceptors: [generateInterceptors(), ...(options?.interceptors ?? [])], | ||
| }; | ||
| return new TaskHubGrpcClient(hostAddress, innerOptions); | ||
| } | ||
|
|
||
| /** | ||
| * Schedules a new workflow using the DurableTask client. | ||
| * | ||
| * @param {TWorkflow | string} workflow - The Workflow or the name of the workflow to be scheduled. | ||
| * @return {Promise<string>} A Promise resolving to the unique ID of the scheduled workflow instance. | ||
| */ | ||
| public async scheduleNewWorkflow( | ||
kaibocai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| workflow: TWorkflow | string, | ||
| input?: any, | ||
| instanceId?: string, | ||
| startAt?: Date, | ||
| ): Promise<string> { | ||
| if (typeof workflow === "string") { | ||
| return await this._innerClient.scheduleNewOrchestration(workflow, input, instanceId, startAt); | ||
| } | ||
| return await this._innerClient.scheduleNewOrchestration(getFunctionName(workflow), input, instanceId, startAt); | ||
| } | ||
|
|
||
| /** | ||
| * Terminates the workflow associated with the provided instance id. | ||
| * | ||
| * @param {string} workflowInstanceId - Workflow instance id to terminate. | ||
| * @param {any} output - The optional output to set for the terminated workflow instance. | ||
| */ | ||
| public async terminateWorkflow(workflowInstanceId: string, output: any) { | ||
| await this._innerClient.terminateOrchestration(workflowInstanceId, output); | ||
| } | ||
|
|
||
| /** | ||
| * Fetches workflow instance metadata from the configured durable store. | ||
| * | ||
| * @param {string} workflowInstanceId - The unique identifier of the workflow instance to fetch. | ||
| * @param {boolean} getInputsAndOutputs - Indicates whether to fetch the workflow instance's | ||
| * inputs, outputs, and custom status (true) or omit them (false). | ||
| * @returns {Promise<WorkflowState | undefined>} A Promise that resolves to a metadata record describing | ||
| * the workflow instance and its execution status, or undefined | ||
| * if the instance is not found. | ||
| */ | ||
| public async getWorkflowState( | ||
| workflowInstanceId: string, | ||
| getInputsAndOutputs: boolean, | ||
| ): Promise<WorkflowState | undefined> { | ||
| const state = await this._innerClient.getOrchestrationState(workflowInstanceId, getInputsAndOutputs); | ||
| if (state !== undefined) { | ||
| return new WorkflowState(state); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Waits for a workflow to start running and returns a {@link WorkflowState} object | ||
| * containing metadata about the started instance, and optionally, its input, output, | ||
| * and custom status payloads. | ||
| * | ||
| * A "started" workflow instance refers to any instance not in the Pending state. | ||
| * | ||
| * If a workflow instance is already running when this method is called, it returns immediately. | ||
| * | ||
| * @param {string} workflowInstanceId - The unique identifier of the workflow instance to wait for. | ||
| * @param {boolean} fetchPayloads - Indicates whether to fetch the workflow instance's | ||
| * inputs, outputs (true) or omit them (false). | ||
| * @param {number} timeout - The amount of time, in seconds, to wait for the workflow instance to start. | ||
| * @returns {Promise<WorkflowState | undefined>} A Promise that resolves to the workflow instance metadata | ||
| * or undefined if no such instance is found. | ||
| */ | ||
| public async waitForWorkflowStart( | ||
| workflowInstanceId: string, | ||
| fetchPayloads?: boolean, | ||
| timeout?: number, | ||
| ): Promise<WorkflowState | undefined> { | ||
| const state = await this._innerClient.waitForOrchestrationStart(workflowInstanceId, fetchPayloads, timeout); | ||
| if (state !== undefined) { | ||
| return new WorkflowState(state); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Waits for a workflow to complete running and returns a {@link WorkflowState} object | ||
| * containing metadata about the completed instance, and optionally, its input, output, | ||
| * and custom status payloads. | ||
| * | ||
| * A "completed" workflow instance refers to any instance in one of the terminal states. | ||
| * For example, the Completed, Failed, or Terminated states. | ||
| * | ||
| * If a workflow instance is already running when this method is called, it returns immediately. | ||
| * | ||
| * @param {string} workflowInstanceId - The unique identifier of the workflow instance to wait for. | ||
| * @param {boolean} fetchPayloads - Indicates whether to fetch the workflow instance's | ||
| * inputs, outputs (true) or omit them (false). | ||
| * @param {number} timeout - The amount of time, in seconds, to wait for the workflow instance to start. | ||
| * @returns {Promise<WorkflowState | undefined>} A Promise that resolves to the workflow instance metadata | ||
| * or undefined if no such instance is found. | ||
| */ | ||
| public async waitForWorkflowCompletion( | ||
| workflowInstanceId: string, | ||
| fetchPayloads = true, | ||
| timeout: number, | ||
kaibocai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ): Promise<WorkflowState | undefined> { | ||
| const state = await this._innerClient.waitForOrchestrationCompletion(workflowInstanceId, fetchPayloads, timeout); | ||
| if (state != undefined) { | ||
| return new WorkflowState(state); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sends an event notification message to an awaiting workflow instance. | ||
| * | ||
| * This method triggers the specified event in a running workflow instance, | ||
| * allowing the workflow to respond to the event if it has defined event handlers. | ||
| * | ||
| * @param {string} workflowInstanceId - The unique identifier of the workflow instance that will handle the event. | ||
| * @param {string} eventName - The name of the event. Event names are case-insensitive. | ||
| * @param {any} [eventPayload] - An optional serializable data payload to include with the event. | ||
| */ | ||
| public async raiseEvent(workflowInstanceId: string, eventName: string, eventPayload?: any) { | ||
| this._innerClient.raiseOrchestrationEvent(workflowInstanceId, eventName, eventPayload); | ||
| } | ||
|
|
||
| /** | ||
| * Purges the workflow instance state from the workflow state store. | ||
| * | ||
| * This method removes the persisted state associated with a workflow instance from the state store. | ||
| * | ||
| * @param {string} workflowInstanceId - The unique identifier of the workflow instance to purge. | ||
| * @return {Promise<boolean>} A Promise that resolves to true if the workflow state was found and purged successfully, otherwise false. | ||
| */ | ||
| public async purgeWorkflow(workflowInstanceId: string): Promise<boolean> { | ||
| const purgeResult = await this._innerClient.purgeOrchestration(workflowInstanceId); | ||
| if (purgeResult !== undefined) { | ||
| return purgeResult.deletedInstanceCount > 0; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Closes the inner DurableTask client and shutdown the GRPC channel. | ||
| */ | ||
| public async stop() { | ||
| await this._innerClient.stop(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| Copyright 2022 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { FailureDetails } from "kaibocai-durabletask-js/task/failure-details"; | ||
|
|
||
| export class WorkflowFailureDetails { | ||
| private readonly failureDetails: FailureDetails; | ||
|
|
||
| constructor(failureDetails: FailureDetails) { | ||
| this.failureDetails = failureDetails; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the error type, which is the namespace-qualified exception type name. | ||
| * @return {string} The error type. | ||
| */ | ||
| public getErrorType(): string { | ||
| return this.failureDetails.errorType; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the error message. | ||
| * @return {string} The error message. | ||
| */ | ||
| public getErrorMessage(): string { | ||
| return this.failureDetails.message; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the stack trace. | ||
| * @return {string | undefined} The stack trace, or undefined if not available. | ||
| */ | ||
| public getStackTrace(): string | undefined { | ||
| return this.failureDetails.stackTrace; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.