Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| ChildWorkflows | ||
| README.md | ||
| childworkflows.http | ||
| dapr.yaml | ||
| makefile | ||
README.md
Child Workflows
This tutorial demonstrates how a workflow can call child workflows that are part of the same application. Child workflows can be used to break up large workflows into smaller, reusable parts. For more information about child workflows see the Dapr docs.
Inspect the code
Open the ParentWorkflow.cs file in the tutorials/workflow/csharp/child-workflows/ChildWorkflows folder. This file contains the definition for the workflow.
The parent workflow iterates over the input array and schedules an instance of the ChildWorkflow for each of the input elements. The ChildWorkflow is a basic task-chaining workflow that contains a sequence of two activities. When all of the instances of the ChildWorkflow complete, then the parent workflow finishes.
Parent workflow
graph LR
SW((Start
Workflow))
subgraph for each word in the input
GWL[Call child workflow]
end
ALL[Wait until all tasks
are completed]
EW((End
Workflow))
SW --> GWL
GWL --> ALL
ALL --> EW
Child workflow
graph LR
SW((Start
Workflow))
A1[Activity1]
A2[Activity2]
EW((End
Workflow))
SW --> A1
A1 --> A2
A2 --> EW
Run the tutorial
-
Use a terminal to navigate to the
tutorials/workflow/csharp/child-workflowsfolder. -
Build the project using the .NET CLI.
dotnet build ./ChildWorkflows/ -
Use the Dapr CLI to run the Dapr Multi-App run file
```bashdapr run -f .
<!-- END_STEP --> -
Use the POST request in the
childworkflows.httpfile to start the workflow, or use this cURL command:curl -i --request POST \ --url http://localhost:5259/start \ --header 'content-type: application/json' \ --data '["Item 1","Item 2"]'The input of the workflow is an array with two strings:
[ "Item 1", "Item 2" ]The app logs should show both the items in the input values array being processed by each activity in the child workflow as follows:
== APP - childworkflows == Activity1: Received input: Item 1. == APP - childworkflows == Activity2: Received input: Item 1 is processed. == APP - childworkflows == Activity1: Received input: Item 2. == APP - childworkflows == Activity2: Received input: Item 2 is processed. -
Use the GET request in the
childworkflows.httpfile to get the status of the workflow, or use this cURL command:curl --request GET --url http://localhost:3559/v1.0/workflows/dapr/<INSTANCEID>Where
<INSTANCEID>is the workflow instance ID you received in theLocationheader in the previous step.The expected serialized output of the workflow is an array with two strings:
"[\"Item 1 is processed as a child workflow.\",\"Item 2 is processed as a child workflow.\"]" -
Stop the Dapr Multi-App run process by pressing
Ctrl+C.