This directory contains examples of how to author durable orchestrations using the Durable Task Python SDK in conjunction with the Durable Task Scheduler (DTS). Please note that the installation instructions provided below will use the version of DTS directly from the your branch rather than installing through PyPI.
There are 2 separate ways to run an example:
- Using the emulator.
- Using a real scheduler and taskhub.
All the examples by defualt assume that you have a Durable Task Scheduler taskhub created.
The simplest way to create a taskhub is by using the az cli commands:
-
Create a scheduler: az durabletask scheduler create --resource-group --name --location --ip-allowlist "[0.0.0.0/0]" --sku-capacity 1 --sku-name "Dedicated" --tags "{}"
-
Create your taskhub
az durabletask taskhub create --resource-group <testrg> --scheduler-name <testscheduler> --name <testtaskhub>
-
Retrieve the endpoint for the scheduler. This can be done by locating the taskhub in the portal.
-
Set the appropriate environment variables for the TASKHUB and ENDPOINT
export TASKHUB=<taskhubname> export ENDPOINT=<taskhubEndpoint>
-
Since the samples rely on azure identity, ensure the package is installed and up-to-date
python3 -m pip install azure-identity
-
Install the correct packages from the top level of this repository, i.e. durabletask-python/
python3 -m pip install . -
Install the DTS specific packages from the durabletask-python/durabletask-azuremanaged directory
pip3 install -e . -
Grant yourself the
Durable Task Data Contributorrole over your scheduler
The emulator is a simulation of a scheduler and taskhub. It is the 'backend' of the durabletask-azuremanaged system packaged up into an easy to use docker container. For these steps, it is assumed that you are using port 8080.
In order to use the emulator for the examples, perform the following steps:
-
Install docker if it is not already installed.
-
Pull down the docker image for the emulator:
docker pull mcr.microsoft.com/dts/dts-emulator:v0.0.4 -
Run the emulator and wait a few seconds for the container to be ready:
docker run --name dtsemulator -d -p 8080:8080 mcr.microsoft.com/dts/dts-emulator:v0.0.4 -
Set the environment variables that are referenced and used in the examples:
- If you are using windows powershell:
$env:TASKHUB="default"$env:ENDPOINT="http://localhost:8080" - If you are using bash:
export TASKHUB=defaultexport ENDPOINT=http://localhost:8080
- If you are using windows powershell:
-
Finally, edit the examples to change the
token_credentialinput of both theDurableTaskSchedulerWorkerandDurableTaskSchedulerClientto a value ofNone
Now, you can simply execute any of the examples in this directory using python3:
python3 dts_activity_sequence.py