Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com> |
||
---|---|---|
.. | ||
child_workflows | ||
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 parent_child_workflow.py
file in the tutorials/workflow/python/child-workflows/child_workflows
folder. This file contains the definition for the workflows and activities.
The parent workflow iterates over the input array and schedules an instance of the child_workflow
for each of the input elements. The child_workflow
is a basic task-chaining workflow that contains a sequence of two activities. When all of the instances of the child_workflow
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/python/child-workflows/child_workflows
folder. -
Install the dependencies using pip:
pip3 install -r requirements.txt
-
Navigate one level back to the
child-workflows
folder and use the Dapr CLI to run the Dapr Multi-App run file```bash
dapr run -f .
<!-- END_STEP -->
-
Use the POST request in the
childworkflows.http
file 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.http
file 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 theinstance_id
property 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
.