|
1 | 1 | # Examples |
2 | 2 |
|
3 | | -This directory contains examples of how to author durable orchestrations using the Durable Task Python SDK in conjunction with the Durable Task Scheduler (DTS). |
| 3 | +This directory contains examples of how to author durable orchestrations |
| 4 | +using the Durable Task Python SDK in conjunction with the |
| 5 | +Durable Task Scheduler (DTS). |
4 | 6 |
|
5 | 7 | ## Prerequisites |
| 8 | + |
6 | 9 | If using a deployed Durable Task Scheduler: |
7 | | - - [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) |
8 | | - - [`az durabletask` CLI extension](https://learn.microsoft.com/en-us/cli/azure/durabletask?view=azure-cli-latest) |
| 10 | + |
| 11 | +- [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) |
| 12 | +- [`az durabletask` CLI extension](https://learn.microsoft.com/cli/azure/durabletask?view=azure-cli-latest) |
9 | 13 |
|
10 | 14 | ## Running the Examples |
| 15 | + |
11 | 16 | There are two separate ways to run an example: |
12 | 17 |
|
13 | 18 | - Using the Emulator (recommended for learning and development) |
14 | | -- Using a deployed Scheduler and Taskhub in Azure |
| 19 | +- Using a deployed Scheduler and Taskhub in Azure |
15 | 20 |
|
16 | 21 | ### Running with the Emulator |
17 | | -We recommend using the emulator for learning and development as it's faster to set up and doesn't require any Azure resources. The emulator simulates a scheduler and taskhub, packaged into an easy-to-use Docker container. |
| 22 | + |
| 23 | +We recommend using the emulator for learning and development as it's |
| 24 | +faster to set up and doesn't require any Azure resources. The emulator |
| 25 | +simulates a scheduler and taskhub, packaged into an easy-to-use |
| 26 | +Docker container. |
18 | 27 |
|
19 | 28 | 1. Install Docker: If it is not already installed. |
20 | 29 |
|
21 | | -2. Pull the Docker Image for the Emulator: |
22 | | -```bash |
23 | | -docker pull mcr.microsoft.com/dts/dts-emulator:v0.0.6 |
24 | | -``` |
| 30 | +1. Pull the Docker Image for the Emulator: |
25 | 31 |
|
26 | | -3. Run the Emulator: Wait a few seconds for the container to be ready. |
27 | | -```bash |
28 | | -docker run --name dtsemulator -d -p 8080:8080 mcr.microsoft.com/dts/dts-emulator:v0.0.6 |
29 | | -``` |
| 32 | + ```bash |
| 33 | + docker pull mcr.microsoft.com/dts/dts-emulator:latest |
| 34 | + ``` |
30 | 35 |
|
31 | | -4. Install the Required Packages: |
32 | | -```bash |
33 | | -pip install -r requirements.txt |
34 | | -``` |
| 36 | +1. Run the Emulator: Wait a few seconds for the container to be ready. |
| 37 | + |
| 38 | + ```bash |
| 39 | + docker run --name dtsemulator -d -p 8080:8080 mcr.microsoft.com/dts/dts-emulator:latest |
| 40 | + ``` |
| 41 | + |
| 42 | +1. Create a Python virtual environment (recommended): |
| 43 | + |
| 44 | + ```bash |
| 45 | + python -m venv .venv |
| 46 | + ``` |
35 | 47 |
|
36 | | -Note: The example code has been updated to use the default emulator settings automatically (endpoint: http://localhost:8080, taskhub: default). You don't need to set any environment variables. |
| 48 | + Activate the virtual environment: |
| 49 | + |
| 50 | + Bash: |
| 51 | + |
| 52 | + ```bash |
| 53 | + source .venv/bin/activate |
| 54 | + ``` |
| 55 | + |
| 56 | + PowerShell: |
| 57 | + |
| 58 | + ```powershell |
| 59 | + .\.venv\Scripts\Activate.ps1 |
| 60 | + ``` |
| 61 | + |
| 62 | +1. Install the Required Packages: |
| 63 | + |
| 64 | + ```bash |
| 65 | + pip install -r requirements.txt |
| 66 | + ``` |
| 67 | + |
| 68 | + If you are running from a local clone of the repository, install the |
| 69 | + local packages in editable mode instead (run this from the repository |
| 70 | + root, not the `examples/` directory): |
| 71 | + |
| 72 | + ```bash |
| 73 | + pip install -e . -e ./durabletask-azuremanaged |
| 74 | + ``` |
| 75 | + |
| 76 | +> [!NOTE] |
| 77 | +> The example code uses the default emulator settings |
| 78 | +> automatically (endpoint: `http://localhost:8080`, taskhub: `default`). |
| 79 | +> You don't need to set any environment variables. |
37 | 80 |
|
38 | 81 | ### Running with a Deployed Scheduler and Taskhub Resource in Azure |
39 | | -For production scenarios or when you're ready to deploy to Azure, you can create a taskhub using the Azure CLI: |
| 82 | + |
| 83 | +For production scenarios or when you're ready to deploy to Azure, you |
| 84 | +can create a taskhub using the Azure CLI: |
40 | 85 |
|
41 | 86 | 1. Create a Scheduler: |
42 | | -```bash |
43 | | -az durabletask scheduler create --resource-group <testrg> --name <testscheduler> --location <eastus> --ip-allowlist "[0.0.0.0/0]" --sku-capacity 1 --sku-name "Dedicated" --tags "{'myattribute':'myvalue'}" |
44 | | -``` |
45 | 87 |
|
46 | | -2. Create Your Taskhub: |
47 | | -```bash |
48 | | -az durabletask taskhub create --resource-group <testrg> --scheduler-name <testscheduler> --name <testtaskhub> |
49 | | -``` |
| 88 | + Bash: |
50 | 89 |
|
51 | | -3. Retrieve the Endpoint for the Scheduler: Locate the taskhub in the Azure portal to find the endpoint. |
| 90 | + ```bash |
| 91 | + az durabletask scheduler create \ |
| 92 | + --resource-group <testrg> \ |
| 93 | + --name <testscheduler> \ |
| 94 | + --location <eastus> \ |
| 95 | + --ip-allowlist "[0.0.0.0/0]" \ |
| 96 | + --sku-capacity 1 \ |
| 97 | + --sku-name "Dedicated" \ |
| 98 | + --tags "{'myattribute':'myvalue'}" |
| 99 | + ``` |
52 | 100 |
|
53 | | -4. Set the Environment Variables: |
54 | | -Bash: |
55 | | -```bash |
56 | | -export TASKHUB=<taskhubname> |
57 | | -export ENDPOINT=<taskhubEndpoint> |
58 | | -``` |
59 | | -Powershell: |
60 | | -```powershell |
61 | | -$env:TASKHUB = "<taskhubname>" |
62 | | -$env:ENDPOINT = "<taskhubEndpoint>" |
63 | | -``` |
| 101 | + PowerShell: |
64 | 102 |
|
65 | | -5. Install the Required Packages: |
66 | | -```bash |
67 | | -pip install -r requirements.txt |
68 | | -``` |
| 103 | + ```powershell |
| 104 | + az durabletask scheduler create ` |
| 105 | + --resource-group <testrg> ` |
| 106 | + --name <testscheduler> ` |
| 107 | + --location <eastus> ` |
| 108 | + --ip-allowlist "[0.0.0.0/0]" ` |
| 109 | + --sku-capacity 1 ` |
| 110 | + --sku-name "Dedicated" ` |
| 111 | + --tags "{'myattribute':'myvalue'}" |
| 112 | + ``` |
| 113 | + |
| 114 | +1. Create Your Taskhub: |
| 115 | + |
| 116 | + Bash: |
| 117 | + |
| 118 | + ```bash |
| 119 | + az durabletask taskhub create \ |
| 120 | + --resource-group <testrg> \ |
| 121 | + --scheduler-name <testscheduler> \ |
| 122 | + --name <testtaskhub> |
| 123 | + ``` |
| 124 | + |
| 125 | + PowerShell: |
| 126 | + |
| 127 | + ```powershell |
| 128 | + az durabletask taskhub create ` |
| 129 | + --resource-group <testrg> ` |
| 130 | + --scheduler-name <testscheduler> ` |
| 131 | + --name <testtaskhub> |
| 132 | + ``` |
| 133 | + |
| 134 | +1. Retrieve the Endpoint for the Scheduler: Locate the taskhub in the |
| 135 | + Azure portal to find the endpoint. |
| 136 | + |
| 137 | +1. Set the Environment Variables: |
| 138 | + |
| 139 | + Bash: |
| 140 | + |
| 141 | + ```bash |
| 142 | + export TASKHUB=<taskhubname> |
| 143 | + export ENDPOINT=<taskhubEndpoint> |
| 144 | + ``` |
| 145 | + |
| 146 | + PowerShell: |
| 147 | + |
| 148 | + ```powershell |
| 149 | + $env:TASKHUB = "<taskhubname>" |
| 150 | + $env:ENDPOINT = "<taskhubEndpoint>" |
| 151 | + ``` |
| 152 | + |
| 153 | +1. Install the Required Packages: |
| 154 | + |
| 155 | + ```bash |
| 156 | + pip install -r requirements.txt |
| 157 | + ``` |
| 158 | + |
| 159 | +### Executing the Examples |
69 | 160 |
|
70 | | -### Running the Examples |
71 | 161 | You can now execute any of the examples in this directory using Python: |
72 | 162 |
|
73 | 163 | ```bash |
74 | | -python3 example_file.py |
| 164 | +python activity_sequence.py |
75 | 165 | ``` |
76 | 166 |
|
77 | | -### Review Orchestration History and Status in the Durable Task Scheduler Dashboard |
78 | | -To access the Durable Task Scheduler Dashboard, follow these steps: |
| 167 | +### Review Orchestration History and Status |
79 | 168 |
|
80 | | -- **Using the Emulator**: By default, the dashboard runs on portal 8082. Navigate to http://localhost:8082 and click on the default task hub. |
| 169 | +To access the Durable Task Scheduler Dashboard, follow these steps: |
81 | 170 |
|
82 | | -- **Using a Deployed Scheduler**: Navigate to the Scheduler resource. Then, go to the Task Hub subresource that you are using and click on the dashboard URL in the top right corner. |
| 171 | +- **Using the Emulator**: By default, the dashboard runs on port 8082. |
| 172 | + Navigate to <http://localhost:8082> and click on the default task hub. |
83 | 173 |
|
84 | | -```sh |
85 | | -python3 activity_sequence.py |
86 | | -``` |
| 174 | +- **Using a Deployed Scheduler**: Navigate to the Scheduler resource. |
| 175 | + Then, go to the Task Hub subresource that you are using and click on |
| 176 | + the dashboard URL in the top right corner. |
0 commit comments