Skip to content
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

Fixes class of canceled on client issues #614

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/workflow/authoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
```bash
# Install
npm install
npm install --save-dev @types/readline-sync

# Run the example
npm run start:dapr:activity-sequence
Expand Down
19 changes: 12 additions & 7 deletions examples/workflow/authoring/src/activity-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ limitations under the License.

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

const daprHost = "localhost";
const daprPort = "50001";
const workflowRuntime = new WorkflowRuntime({
daprHost,
daprPort,
});

async function start() {
// Update the gRPC client and worker to use a local address and port
const daprHost = "localhost";
const daprPort = "50001";

const workflowClient = new DaprWorkflowClient({
daprHost,
daprPort,
});
const workflowRuntime = new WorkflowRuntime({
daprHost,
daprPort,
});

const hello = async (_: WorkflowActivityContext, name: string) => {
return `Hello ${name}!`;
Expand Down Expand Up @@ -66,13 +68,16 @@ async function start() {
console.error("Error scheduling or waiting for orchestration:", error);
}

await workflowRuntime.stop();
await workflowClient.stop();

// stop the dapr side car
process.exit(0);
}

process.on('SIGTERM', () => {
workflowRuntime.stop();
})

start().catch((e) => {
console.error(e);
process.exit(1);
Expand Down
20 changes: 12 additions & 8 deletions examples/workflow/authoring/src/fanout-fanin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ import {
TWorkflow,
} from "@dapr/dapr";

const daprHost = "localhost";
const daprPort = "50001";
const workflowRuntime = new WorkflowRuntime({
daprHost,
daprPort,
});

// 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 daprHost = "localhost";
const daprPort = "50001";
const workflowClient = new DaprWorkflowClient({
daprHost,
daprPort,
});
const workflowRuntime = new WorkflowRuntime({
daprHost,
daprPort,
});

function getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
Expand Down Expand Up @@ -99,14 +100,17 @@ async function start() {
console.error("Error scheduling or waiting for orchestration:", error);
}

// stop worker and client
await workflowRuntime.stop();
// stop client
await workflowClient.stop();

// stop the dapr side car
process.exit(0);
}

process.on('SIGTERM', () => {
workflowRuntime.stop();
})

start().catch((e) => {
console.error(e);
process.exit(1);
Expand Down
20 changes: 12 additions & 8 deletions examples/workflow/authoring/src/human-interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import {
} from "@dapr/dapr";
import * as readlineSync from "readline-sync";

const daprHost = "localhost";
const daprPort = "50001";
const workflowRuntime = new WorkflowRuntime({
daprHost,
daprPort,
});

// Wrap the entire code in an immediately-invoked async function
async function start() {
class Order {
Expand All @@ -39,16 +46,10 @@ async function start() {
}

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

// Activity function that sends an approval request to the manager
const sendApprovalRequest = async (_: WorkflowActivityContext, order: Order) => {
Expand Down Expand Up @@ -122,8 +123,7 @@ async function start() {
console.error("Error scheduling or waiting for orchestration:", error);
}

// stop worker and client
await workflowRuntime.stop();
// stop client
await workflowClient.stop();

// stop the dapr side car
Expand All @@ -139,6 +139,10 @@ async function promptForApproval(approver: string, workflowClient: DaprWorkflowC
}
}

process.on('SIGTERM', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
grpc/grpc-node#2233

Proper fix would be adding error handler to take care of CANCELLED status. Although it is not critical for tutorials but for general javascript SDK client, it should be handled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will take a look. thank you for this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it would need a better handling through some error handler kind of mechanism.

workflowRuntime.stop();
})

start().catch((e) => {
console.error(e);
process.exit(1);
Expand Down
Loading