quickstarts/tutorials/workflow/python/child-workflows
Marc Duiker 6e91aeac09
Update naming
Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com>
2025-05-15 07:22:51 +00:00
..
child_workflows Add univorn dependency 2025-05-14 11:04:05 +00:00
README.md Update naming 2025-05-15 07:22:51 +00:00
childworkflows.http Update naming 2025-05-15 07:22:51 +00:00
dapr.yaml Add child workflows 2025-05-08 11:05:34 +02:00
makefile Add child workflows 2025-05-08 11:05:34 +02:00

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

  1. Use a terminal to navigate to the tutorials/workflow/python/child-workflows/child_workflows folder.

  2. Install the dependencies using pip:

    pip3 install -r requirements.txt
    
  3. 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 -->
    
    
  4. 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.
    
  5. 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 the instance_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.\"]"
    
  6. Stop the Dapr Multi-App run process by pressing Ctrl+C.