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

Modify workflow sample README #1210

Closed
wants to merge 3 commits into from
Closed
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
153 changes: 148 additions & 5 deletions examples/Workflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ This Dapr workflow example shows how to create a Dapr workflow (`Workflow`) and
## Optional Setup
Dapr workflow, as well as this example program, now support authentication through the use of API tokens. For more information on this, view the following document: [API Token](https://github.com/dapr/dotnet-sdk/blob/master/docs/api-tokens.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider also making it clear that there must be a storage component spec in their default component directory that includes actorStateStore: true or none of these examples will work as it'll fail to connect.


## Projects in sample

## Console App
This sample contains a single [WorkflowConsoleApp](./WorkflowConsoleApp) .NET project.
It utilizes the workflow SDK as well as the workflow management API for simulating inventory management and sale of goods in a store.
The main `Program.cs` file contains the main setup of the app, the registration of the workflow and its activities, and interaction with the user. The workflow definition is found in the `Workflows` directory and the workflow activity definitions are found in the `Activities` directory.
Expand All @@ -32,8 +31,6 @@ This sample also contains a [WorkflowUnitTest](./WorkflowUnitTest) .NET project
It works by creating an instance of the `OrderProcessingWorkflow` (defined in the `WorkflowConsoleApp` project), mocking activity calls, and testing the inputs and outputs.
The tests also verify that outputs of the workflow.

## Running the console app example

To run the workflow web app locally, two separate terminal windows are required.
In the first terminal window, from the `WorkflowConsoleApp` directory, run the following command to start the program itself:

Expand Down Expand Up @@ -132,4 +129,150 @@ info: WorkflowConsoleApp.Activities.NotifyActivity[0]
Order 1234 processed successfully!
```

If you have Zipkin configured for Dapr locally on your machine, then you can view the workflow trace spans in the Zipkin web UI (typically at http://localhost:9411/zipkin/).
If you have Zipkin configured for Dapr locally on your machine, then you can view the workflow trace spans in the Zipkin web UI (typically at http://localhost:9411/zipkin/).

## Task Chaining
Details can be found in Dapr [Workflow Patterns Task Chaining](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-patterns/#task-chaining).

To run this sample, in the first terminal window run the following command from the WorkflowTaskChaining directory
```
Copy link
Contributor

Choose a reason for hiding this comment

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

tun -> run

dotnet tun
```
Next, in a separate terminal window, start the dapr sidecar:
```
dapr run --app-id wfapp --dapr-grpc-port 4001 --dapr-http-port 3500
```
The stdout of the workflow app should look like the following:
```
Workflow Started.
Step 1: Received input: 42.
Step 2: Received input: 43.
Step 3: Received input: 86.
Workflow state: Completed
Workflow result: 43 86 84
```

## Fan-Out/Fan-In
Details can be found in Dapr [Workflow Patterns Fan-Out/Fan-In](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-patterns/#fan-outfan-in).

To run this sample, in the first terminal window run the following command from the WorkflowFanOutFanin directory
```
Copy link
Contributor

Choose a reason for hiding this comment

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

tun -> run

dotnet tun
```
Next, in a separate terminal window, start the dapr sidecar:
```
dapr run --app-id wfapp --dapr-grpc-port 4001 --dapr-http-port 3500
```
The stdout of the workflow app should look like the following:
```
Workflow Started.
calling task 3 ...
calling task 2 ...
calling task 1 ...
Workflow state: Completed
```
The order of tasks log is uncertain because they are executed concurrently.

## Monitor
Details can be found in Dapr [Workflow Patterns Monitor](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-patterns/#monitor).

To run this sample, in the first terminal window run the following command from the WorkflowMonitor directory
```
Copy link
Contributor

Choose a reason for hiding this comment

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

tun -> run

dotnet tun
```
Next, in a separate terminal window, start the dapr sidecar:
```
dapr run --app-id wfapp --dapr-grpc-port 4001 --dapr-http-port 3500
```
The stdout of the workflow app should look like the following:
```
Workflow Started.
...
Status is unhealthy. Set check interval to 1s
This job is healthy
This job is unhealthy
Status is unhealthy. Set check interval to 1s
Status is unhealthy. Set check interval to 1s
...
```

## External System Interaction
Details can be found in Dapr [Workflow Patterns External System Interaction](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-patterns/#external-system-interaction).

To run this sample, in the first terminal window run the following command from the WorkflowMonitor directory
```
Copy link
Contributor

Choose a reason for hiding this comment

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

tun -> run

dotnet tun
```
Next, in a separate terminal window, start the dapr sidecar:
```
dapr run --app-id wfapp --dapr-grpc-port 4001 --dapr-http-port 3500
```
The stdout of the workflow app should look like the following:
```
// If press enter
Workflow Started.
Press [ENTER] in 10s to approve this workflow.
Approved.
Workflow demo-workflow-994ed458 is approved.
Running Approval activity ...
Approve Activity finished
Workflow state: Completed

// if do nothing
Workflow Started.
Press [ENTER] in 10s to approve this workflow.
Rejected.
Approval timeout.
Workflow demo-workflow-c9036657 is rejected.
Running Reject activity ...
Approval timeout.
Reject Activity finished
Workflow state: Completed
```

## Sub-Workflow
The sub-workflow pattern allows you to call a workflow from another workflow.
The `DemoWorkflow` class defines the workflow. It calls a sub-workflow `DemoSubWorkflow` to do the work. See the code snippet below:
```c#
public class DemoWorkflow : Workflow<string, bool>
{
public override async Task<bool> RunAsync(WorkflowContext context, string instanceId)
{
Console.WriteLine($"Workflow {instanceId} Started.");
string subInstanceId = instanceId + "-sub";
ChildWorkflowTaskOptions options = new ChildWorkflowTaskOptions(subInstanceId);
await context.CallChildWorkflowAsync<bool>(nameof(DemoSubWorkflow), "Hello, sub-workflow", options);
return true;
}
}
```

The `DemoSubWorkflow` class defines the sub-workflow. It prints its instanceID and input, and then pauses for 5 seconds to simulate transaction processing. See the code snippet below:
```c#
public class DemoSubWorkflow : Workflow<string, bool>
{
public override async Task<bool> RunAsync(WorkflowContext context, string input)
{
Console.WriteLine($"Workflow {context.InstanceId} Started.");
Console.WriteLine($"Received input: {input}.");
await context.CreateTimer(TimeSpan.FromSeconds(5));
return true;
}
}
```
To run this sample, in the first terminal window run the following command from the WorkflowMonitor directory
```
Copy link
Contributor

Choose a reason for hiding this comment

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

tun -> run

dotnet tun
```
Next, in a separate terminal window, start the dapr sidecar:
```
dapr run --app-id wfapp --dapr-grpc-port 4001 --dapr-http-port 3500
```
The stdout of the workflow app should look like the following:
```
Workflow Started.
Workflow demo-workflow-ee513152 Started.
Workflow demo-workflow-ee513152-sub Started.
Received input: Hello, sub-workflow.
Workflow demo-workflow-ee513152 state: Completed
```
Loading