Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Examples

This directory contains examples of how to author durable orchestrations using the Durable Task Python SDK.

Prerequisites

All the examples assume that you have a Durable Task-compatible sidecar running locally. There are two options for this:

  1. Install the latest version of the Dapr CLI, which contains and exposes an embedded version of the Durable Task engine. The setup process (which requires Docker) will configure the workflow engine to store state in a local Redis container.

  2. Run the Durable Task Sidecar project locally (requires Go 1.18 or higher). Orchestration state will be stored in a local sqlite database.

    go install github.com/dapr/durabletask-go@main
    durabletask-go --port 4001

Automated Testing

These examples can be tested automatically using mechanical-markdown, which validates that the examples run correctly and produce expected output.

To install mechanical-markdown:

python3 -m venv .venv
source .venv/bin/activate
pip install -e ../.
pip install mechanical-markdown

To see what commands would be run without executing them:

mm.py -d README.md

To run all examples and validate their output:

mm.py README.md

Running the Examples

With one of the sidecars running, you can execute any of the examples in this directory using python3:

python3 ./activity_sequence.py

In some cases, the sample may require command-line parameters or user inputs. In these cases, the sample will print out instructions on how to proceed.

Activity Sequence Example

This example demonstrates the function chaining pattern, where an orchestrator schedules three activity calls in a sequence.

python activity_sequence.py

Fan-out/Fan-in Example

This example demonstrates parallel execution, where an orchestrator schedules a dynamic number of activity calls in parallel, waits for all of them to complete, and then performs an aggregation on the results.

python fanout_fanin.py

Human Interaction Example

This example demonstrates how an orchestrator can wait for external events (like human approval) with a timeout. If the approval isn't received within the specified timeout, the order is automatically cancelled.

{ sleep 2; printf '\n'; } | python human_interaction.py --timeout 20 --approver PYTHON-CI

List of examples

  • Activity sequence: Orchestration that schedules three activity calls in a sequence.
  • Fan-out/fan-in: Orchestration that schedules a dynamic number of activity calls in parallel, waits for all of them to complete, and then performs an aggregation on the results.
  • Human interaction: Orchestration that waits for a human to approve an order before continuing.