quickstarts/tutorials/workflow/python/fan-out-fan-in
Marc Duiker 6e91aeac09
Update naming
Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com>
2025-05-15 07:22:51 +00:00
..
fan_out_fan_in Add univorn dependency 2025-05-14 11:04:05 +00:00
README.md Update naming 2025-05-15 07:22:51 +00:00
dapr.yaml Change import, add task chaining and fan-in fan-out 2025-05-07 14:13:51 +02:00
fanoutfanin.http Update naming 2025-05-15 07:22:51 +00:00
makefile Change import, add task chaining and fan-in fan-out 2025-05-07 14:13:51 +02:00

README.md

Fan-out/Fan-in

This tutorial demonstrates how to author a workflow where multiple independent tasks can be scheduled and executed simultaneously. The workflow can either wait until all tasks are completed to proceed, or continue when the fastest task is completed. For more information about the fan-out/fan-in pattern see the Dapr docs.

Inspect the code

Open the fanoutfanin_workflow.py file in the tutorials/workflow/python/fan-out-fan-in/fan_out_fan_in folder. This file contains the definition for the workflow.

graph LR
   SW((Start
   Workflow))
   subgraph for each word in the input
    GWL[get_word_length]
   end
   SHORT[Select the
   shortest word]
   ALL[Wait until all tasks
   are completed]
   EW((End
   Workflow))
   SW --> GWL
   GWL --> ALL
   ALL --> SHORT
   SHORT --> EW

Run the tutorial

  1. Use a terminal to navigate to the tutorials/workflow/python/fan-out-fan-in/fan_out_fan_in folder.

  2. Install the dependencies using pip:

    pip3 install -r requirements.txt
    
  3. Navigate back one level to the fan-out-fan-in 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 fanoutfanin.http file to start the workflow, or use this cURL command:

    curl -i --request POST \
    --url http://localhost:5256/start \
    --header 'content-type: application/json' \
    --data '["which","word","is","the","shortest"]'
    

    The input for the workflow is an array of strings:

    [
        "which",
        "word",
        "is",
        "the",
        "shortest"
    ]
    

    The expected app logs are as follows:

    == APP - fanoutfanin == get_word_length: Received input: word.
    == APP - fanoutfanin == get_word_length: Received input: is.
    == APP - fanoutfanin == get_word_length: Received input: the.
    == APP - fanoutfanin == get_word_length: Received input: shortest.
    == APP - fanoutfanin == get_word_length: Received input: which.
    

    Note that the order of the logs may vary.

  5. Use the GET request in the fanoutfanin.http file to get the status of the workflow, or use this cURL command:

    curl --request GET --url http://localhost:3556/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:

    "\"is\""
    
  6. Stop the Dapr Multi-App run process by pressing Ctrl+C.