Skip to content

Commit 2ac243c

Browse files
committed
copyedit and add arm/bicep
Signed-off-by: Hannah Hunter <[email protected]>
1 parent 531da5f commit 2ac243c

File tree

1 file changed

+137
-19
lines changed

1 file changed

+137
-19
lines changed

articles/azure-functions/durable-task-scheduler/durable-task-scheduler-auto-purge.md

Lines changed: 137 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,41 @@
22
title: Set autopurge retention policies for Azure Functions Durable Task Scheduler (preview)
33
description: Learn about how and why you'd want to configure autopurge retention policies for Durable Task Scheduler.
44
ms.topic: conceptual
5-
ms.date: 04/17/2025
5+
ms.date: 04/28/2025
66
---
77

8-
# Set autopurge retention policies for Azure Functions durable task scheduler (preview)
8+
# Set autopurge retention policies for Azure Functions Durable Task Scheduler (preview)
99

1010
Orchestration history data should be purged periodically to free up storage resources. Otherwise, the app will likely observe performance degradation as history data accumulates overtime. The Durable Task Scheduler offers a lightweight, configurable autopurge feature that helps you manage orchestration data clean-up without manual intervention.
1111

12-
Autopurge runs asynchronously in the background. It's optimized to avoid using too many system resources to prevent blocking or delaying other Durable Task operations. While autopurge doesn't run on a precise schedule, the clean-up rate roughly matches your orchestration scheduling rate.
12+
Autopurge operates asynchronously in the background, optimized to minimize system resource usage and prevent interference with other Durable Task operations. Although autopurge doesn't adhere to a strict schedule, its clean-up rate generally aligns with your orchestration scheduling rate.
1313

14-
## Enable autopurge
14+
## How it works
1515

16-
Autopurge is an opt-in feature. Enable it by defining retention policies that control how long to keep the data of orchestrations in certain statuses. The autopurge feature covers **completed, failed, canceled, or terminated** statuses only. It does not purge data associated of other statuses such as pending or running. Once enabled, autopurge will periodically delete orchestration instances older than the retention period you set.
16+
Autopurge is an opt-in feature. Enable it by defining retention policies that control how long to keep the data of orchestrations in certain statuses. The autopurge feature purges data associated only with the following statuses:
17+
- `Completed`
18+
- `Failed`
19+
- `Canceled`
20+
- `Terminated`
1721

18-
At the moment, retention policies you define will be applied to **ALL** task hubs in a scheduler.
22+
Autopurge ignores data associated with the following statuses:
23+
- `Pending`
24+
- `Running`
1925

20-
You can define retention policies using:
26+
[Once enabled,](#enable-autopurge) autopurge periodically deletes orchestration instances older than the retention period you set.
2127

22-
- Azure Resource Manager (ARM)
23-
- Azure CLI
24-
- Azure portal
28+
> [!NOTE]
29+
> Retention policies you define are applied to **all** task hubs in a scheduler.
30+
31+
### Policy value
2532

26-
When configuring autopurge retention policy, you can set either a *specific* or a *default* policy. Retention value can range from 0 (purge immediately after completion) to the maximum integer value, with the unit being **days**. While there is no limit imposed on the max retention period, it's recommended that you don't keep large volumes of stale orchestration data for too long to ensure efficient use of storage resources and maintain app performance.
33+
Retention value can range from 0 (purge immediately after completion) to the maximum integer value, with the unit being **days**.
34+
35+
Although retention periods have no maximum limit, we recommend you avoid retaining large volumes of stale orchestration data for extended periods. This practice ensures efficient use of storage resources and maintains optimal app performance.
36+
37+
### Types of policies
38+
39+
When configuring an autopurge retention policy, you can set either a *specific* or a *default* policy.
2740

2841
- **Default policy** purges orchestration data *regardless* of `orchestrationState`. The following policy purges orchestration data of all statuses covered by the feature after 2 days:
2942

@@ -33,7 +46,7 @@ When configuring autopurge retention policy, you can set either a *specific* or
3346
}
3447
```
3548

36-
- **Specific policy** specifies purging of orchestration data for specific `orchestrationState`. The following policy tells Durable Task Scheduler to keep *completed* orchestration data for 1 day, after which this data is purged.
49+
- **Specific policy** defines purging of orchestration data for specific `orchestrationState`. The following policy tells Durable Task Scheduler to keep *completed* orchestration data for 1 day, after which this data is purged.
3750

3851
```json
3952
{
@@ -42,7 +55,11 @@ When configuring autopurge retention policy, you can set either a *specific* or
4255
}
4356
```
4457

45-
You can add specific policies to override the default policy that's applied to orchestrations of all statuses. In the example below, the second and third policies override the default policy, so data associated with completed orchestrations is deleted immediately and those associated with failed orchestrations is purged after 60 days. However, because there's no specific policy for orchestrations of statuses canceled and terminated, the default policy still applies so these data are purged after 1 day:
58+
Add specific policies to override the default policy applied to orchestrations, regardless of status. In the example below, the second and third policies override the default policy (`"retentionPeriodInDays": 1`).
59+
- Data associated with completed orchestrations is deleted immediately.
60+
- Data associated with failed orchestrations is purged after 60 days.
61+
62+
However, since no specific policy is set for canceled or terminated orchestrations, the default policy still applies to them, purging their data after 1 day.
4663

4764
```json
4865
[
@@ -62,9 +79,104 @@ You can add specific policies to override the default policy that's applied to o
6279

6380
[For more information, see the API reference spec for Durable Task Scheduler retention policies.](/rest/api/durabletask/retention-policies/create-or-replace?view=rest-durabletask-2025-04-01-preview&preserve-view=true)
6481

82+
## Enable autopurge
83+
84+
You can define retention policies using:
85+
86+
- Bicep
87+
- Azure Resource Manager (ARM)
88+
- Azure CLI
89+
90+
# [Bicep](#tab/bicep)
91+
92+
You can create or update retention policies by adding the `retentionPolicies` configuration to your Bicep file. Make sure you're pulling from the latest preview version.
93+
94+
```bicep
95+
resource exampleResource 'Microsoft.DurableTask/schedulers/retentionPolicies@2025-04-01-preview' = {
96+
parent: parentResource
97+
name: 'example'
98+
properties: {
99+
retentionPolicies: [
100+
{
101+
retentionPeriodInDays: 30
102+
}
103+
{
104+
"retentionPeriodInDays": 0,
105+
"orchestrationState": "Completed"
106+
}
107+
{
108+
retentionPeriodInDays: 60
109+
orchestrationState: 'Failed'
110+
}
111+
]
112+
}
113+
}
114+
```
115+
65116
# [Azure Resource Manager](#tab/arm)
66117

118+
You can create or update retention policies using the Azure Resource Manager API using the following request. Make sure you're pulling from the latest preview version.
119+
120+
```HTTP
121+
PUT https://management.azure.com/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP/providers/Microsoft.DurableTask/schedulers/SCHEDULER_NAME/retentionPolicies/default?api-version=2025-04-01-preview
122+
123+
{
124+
"properties": {
125+
"retentionPolicies": [
126+
{
127+
"retentionPeriodInDays": 1
128+
},
129+
{
130+
"retentionPeriodInDays": 0,
131+
"orchestrationState": "Completed"
132+
},
133+
{
134+
"retentionPeriodInDays": 60,
135+
"orchestrationState": "Failed"
136+
}
137+
]
138+
}
139+
}
140+
```
141+
142+
**Example response**
143+
144+
If creation is successful, you'll see the following response.
145+
146+
```json
147+
{
148+
"properties": {
149+
"provisioningState": "Succeeded",
150+
"retentionPolicies": [
151+
{
152+
"retentionPeriodInDays": 1
153+
},
154+
{
155+
"retentionPeriodInDays": 0,
156+
"orchestrationState": "Completed"
157+
},
158+
{
159+
"retentionPeriodInDays": 60,
160+
"orchestrationState": "Failed"
161+
}
162+
]
163+
},
164+
"id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP/providers/Microsoft.DurableTask/schedulers/SCHEDULER_NAME/retentionPolicies/default",
165+
"name": "default",
166+
"type": "Microsoft.DurableTask/schedulers/retentionPolicies",
167+
"systemData": {
168+
"createdBy": "[email protected]",
169+
"createdByType": "User",
170+
"createdAt": "2025-03-31T23:34:09.612Z",
171+
"lastModifiedBy": "[email protected]",
172+
"lastModifiedByType": "User",
173+
"lastModifiedAt": "2025-03-31T23:34:09.612Z"
174+
}
175+
}
176+
```
177+
67178
# [Azure CLI](#tab/cli)
179+
68180
Create or update the retention policy by running the following:
69181

70182
```azurecli
@@ -89,7 +201,10 @@ Create or update the retention policy by running the following:
89201
}'
90202
```
91203

92-
The following is returned upon successful creation:
204+
**Example response**
205+
206+
If creation is successful, you'll see the following response.
207+
93208
```json
94209
{
95210
"id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.DurableTask/schedulers/SCHEDULER_NAMER/retentionPolicies/default",
@@ -119,14 +234,17 @@ The following is returned upon successful creation:
119234
}
120235
```
121236

122-
# [Azure portal](#tab/portal)
123-
Need
124-
125237
---
126238

127239
## Disable autopurge
240+
241+
# [Bicep](#tab/bicep)
242+
243+
Simply remove `retentionPolicies` from your Bicep
244+
128245
# [Azure Resource Manager](#tab/arm)
129246

247+
130248
# [Azure CLI](#tab/cli)
131249
To disable autopurge, simply delete the retention policies. The Durable Task Scheduler will stop cleaning orchestration data within 5 to 10 minutes.
132250
Need
@@ -135,10 +253,10 @@ Need
135253
az rest --method delete --url "/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.DurableTask/schedulers/SCHEDULER_NAMER/retentionPolicies/default?api-version=2025-04-01-preview"
136254
```
137255

138-
# [Azure portal](#tab/arm)
139-
Experience coming soon!
140256
---
141257

142258

143259

144260
## Next steps
261+
262+
Monitor and manage your orchestration status and history using [the Durable Task Scheduler dashboard](./durable-task-scheduler-dashboard.md).

0 commit comments

Comments
 (0)