diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 3ed790b..9a697e3 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -47,6 +47,12 @@ jobs: go install github.com/dapr/durabletask-go@main durabletask-go --port 4001 & tox -e py${{ matrix.python-version }}-e2e + - name: Run examples + run: | + pip install mechanical-markdown + cd examples + durabletask-go --port 4001 & + mm.py README.md publish: needs: build if: startswith(github.ref, 'refs/tags/v') diff --git a/examples/README.md b/examples/README.md index a6cd847..2a0eac9 100644 --- a/examples/README.md +++ b/examples/README.md @@ -14,9 +14,34 @@ All the examples assume that you have a Durable Task-compatible sidecar running durabletask-go --port 4001 ``` -## Running the examples +## Automated Testing -With one of the sidecars running, you can simply execute any of the examples in this directory using `python3`: +These examples can be tested automatically using [mechanical-markdown](https://github.com/dapr/mechanical-markdown), which validates that the examples run correctly and produce expected output. + +To install mechanical-markdown: + +```bash +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: + +```bash +mm.py -d README.md +``` + +To run all examples and validate their output: + +```bash +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`: ```sh python3 ./activity_sequence.py @@ -24,6 +49,57 @@ 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. + + + +```bash +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. + + + +```bash +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. + + + +```bash +{ sleep 2; printf '\n'; } | python human_interaction.py --timeout 20 --approver PYTHON-CI +``` + + + ## List of examples - [Activity sequence](./activity_sequence.py): Orchestration that schedules three activity calls in a sequence.