Skip to content

Commit 16ecc13

Browse files
Nick GreenfieldNick Greenfield
authored andcommitted
Switch durable backend to Durable Task Scheduler (Consumption SKU)
- Update host.json to use azureManaged storage provider - Add dts.bicep and dts-Access.bicep for scheduler/taskhub provisioning - Update main.bicep with DTS modules and RBAC role assignments - Update processor.bicep to inject DTS connection string app settings - Add durableTaskSchedulers/durableTaskHubs abbreviations - Use Consumption SKU (no capacity) for DTS
1 parent 0e15e86 commit 16ecc13

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed

infra/abbreviations.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
"devicesProvisioningServices": "provs-",
3838
"devicesProvisioningServicesCertificates": "pcert-",
3939
"documentDBDatabaseAccounts": "cosmos-",
40+
"durableTaskSchedulers": "dts-",
41+
"durableTaskHubs": "th-",
4042
"eventGridDomains": "evgd-",
4143
"eventGridDomainsTopics": "evgt-",
4244
"eventGridEventSubscriptions": "evgs-",

infra/app/dts-Access.bicep

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
param principalID string
2+
param roleDefinitionID string
3+
param dtsName string
4+
param principalType string
5+
6+
resource dts 'Microsoft.DurableTask/schedulers@2025-04-01-preview' existing = {
7+
name: dtsName
8+
}
9+
10+
resource dtsRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
11+
name: guid(dts.id, principalID, roleDefinitionID)
12+
scope: dts
13+
properties: {
14+
roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionID)
15+
principalId: principalID
16+
principalType: principalType
17+
}
18+
}

infra/app/dts.bicep

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
param ipAllowlist array
2+
param location string
3+
param tags object = {}
4+
param name string
5+
param taskhubname string
6+
param skuName string
7+
param skuCapacity int = 0
8+
9+
resource dts 'Microsoft.DurableTask/schedulers@2025-04-01-preview' = {
10+
location: location
11+
tags: tags
12+
name: name
13+
properties: {
14+
ipAllowlist: ipAllowlist
15+
sku: skuName == 'Consumption' ? {
16+
name: skuName
17+
} : {
18+
name: skuName
19+
capacity: skuCapacity
20+
}
21+
}
22+
}
23+
24+
resource taskhub 'Microsoft.DurableTask/schedulers/taskHubs@2025-04-01-preview' = {
25+
parent: dts
26+
name: taskhubname
27+
}
28+
29+
output dts_NAME string = dts.name
30+
output dts_URL string = dts.properties.endpoint
31+
output TASKHUB_NAME string = taskhub.name

infra/app/processor.bicep

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ param instanceMemoryMB int = 2048
1313
param maximumInstanceCount int = 100
1414
param identityId string = ''
1515
param identityClientId string = ''
16+
param dtsURL string = ''
17+
param taskHubName string = ''
1618

1719
var applicationInsightsIdentity = 'ClientId=${identityClientId};Authorization=AAD'
1820

21+
// Durable Task Scheduler settings
22+
var dtsSettings = !empty(dtsURL) ? {
23+
DURABLE_TASK_SCHEDULER_CONNECTION_STRING: 'Endpoint=${dtsURL};Authentication=ManagedIdentity;ClientID=${identityClientId}'
24+
TASKHUB_NAME: taskHubName
25+
} : {}
26+
1927
module processor '../core/host/functions-flexconsumption.bicep' = {
2028
name: '${serviceName}-functions-module'
2129
params: {
@@ -28,7 +36,8 @@ module processor '../core/host/functions-flexconsumption.bicep' = {
2836
{
2937
AzureWebJobsStorage__clientId : identityClientId
3038
APPLICATIONINSIGHTS_AUTHENTICATION_STRING: applicationInsightsIdentity
31-
})
39+
},
40+
dtsSettings)
3241
applicationInsightsName: applicationInsightsName
3342
appServicePlanId: appServicePlanId
3443
runtimeName: runtimeName

infra/main.bicep

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@ param resourceGroupName string = ''
2424
param storageAccountName string = ''
2525
param vNetName string = ''
2626
param disableLocalAuth bool = true
27+
param dtsName string = ''
28+
param taskHubName string = ''
29+
param dtsLocation string = location
30+
param dtsSkuName string = 'Consumption'
31+
param dtsCapacity int = 1
32+
@description('Id of the user identity to be used for testing and debugging. This is not required in production. Leave empty if not needed.')
33+
param principalId string = deployer().objectId
2734

2835
var abbrs = loadJsonContent('./abbreviations.json')
2936
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
3037
var tags = { 'azd-env-name': environmentName }
38+
var dtsResourceName = !empty(dtsName) ? dtsName : '${abbrs.durableTaskSchedulers}${resourceToken}'
39+
var taskHubResourceName = !empty(taskHubName) ? taskHubName : '${abbrs.durableTaskHubs}${resourceToken}'
3140

3241
// Organize resources in a resource group
3342
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
@@ -65,6 +74,8 @@ module processor './app/processor.bicep' = {
6574
appSettings: {
6675
}
6776
virtualNetworkSubnetId: serviceVirtualNetwork.outputs.appSubnetID
77+
dtsURL: dts.outputs.dts_URL
78+
taskHubName: dts.outputs.TASKHUB_NAME
6879
}
6980
}
7081

@@ -191,6 +202,50 @@ module appInsightsRoleAssignmentApi './core/monitor/appinsights-access.bicep' =
191202
}
192203
}
193204

205+
// Durable Task Scheduler
206+
module dts './app/dts.bicep' = {
207+
scope: rg
208+
name: 'dtsResource'
209+
params: {
210+
name: dtsResourceName
211+
taskhubname: taskHubResourceName
212+
location: dtsLocation
213+
tags: tags
214+
ipAllowlist: [
215+
'0.0.0.0/0'
216+
]
217+
skuName: dtsSkuName
218+
skuCapacity: dtsCapacity
219+
}
220+
}
221+
222+
// Durable Task Data Contributor role ID
223+
var dtsRoleDefinitionId = '0ad04412-c4d5-4796-b79c-f76d14c8d402'
224+
225+
// Allow access from function app to DTS using user assigned managed identity
226+
module dtsRoleAssignment 'app/dts-Access.bicep' = {
227+
name: 'dtsRoleAssignment'
228+
scope: rg
229+
params: {
230+
roleDefinitionID: dtsRoleDefinitionId
231+
principalID: processorUserAssignedIdentity.outputs.identityPrincipalId
232+
principalType: 'ServicePrincipal'
233+
dtsName: dts.outputs.dts_NAME
234+
}
235+
}
236+
237+
// Allow the deployer identity to access the DTS dashboard
238+
module dtsDashboardRoleAssignment 'app/dts-Access.bicep' = {
239+
name: 'dtsDashboardRoleAssignment'
240+
scope: rg
241+
params: {
242+
roleDefinitionID: dtsRoleDefinitionId
243+
principalID: principalId
244+
principalType: 'User'
245+
dtsName: dts.outputs.dts_NAME
246+
}
247+
}
248+
194249
// App outputs
195250
output APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString
196251
output AZURE_LOCATION string = location

order_processor/host.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
"samplingSettings": {
66
"isEnabled": true,
77
"excludedTypes": "Request"
8+
},
9+
"enableLiveMetricsFilters": true
10+
},
11+
"logLevel": {
12+
"DurableTask.AzureManagedBackend": "Information"
13+
}
14+
},
15+
"extensions": {
16+
"durableTask": {
17+
"hubName": "%TASKHUB_NAME%",
18+
"storageProvider": {
19+
"type": "azureManaged",
20+
"connectionStringName": "DURABLE_TASK_SCHEDULER_CONNECTION_STRING"
821
}
922
}
1023
},

0 commit comments

Comments
 (0)