Skip to content

Commit 53c35e6

Browse files
committed
simplify cleanup
1 parent 38202c9 commit 53c35e6

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

Modules/CIPPCore/Public/Clear-CippDurables.ps1

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
function Clear-CippDurables {
22
[CmdletBinding(SupportsShouldProcess = $true)]
3-
Param()
3+
param()
44
# Collect info
55
$StorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage
66
$FunctionName = $env:WEBSITE_SITE_NAME -replace '-', ''
77

88
# Get orchestrators
99
$InstancesTable = Get-CippTable -TableName ('{0}Instances' -f $FunctionName)
1010
$HistoryTable = Get-CippTable -TableName ('{0}History' -f $FunctionName)
11+
$QueueTable = Get-CippTable -TableName 'CippQueue'
12+
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
13+
14+
Remove-AzDataTable @InstancesTable
15+
Remove-AzDataTable @HistoryTable
16+
Remove-AzDataTable @QueueTable
17+
Remove-AzDataTable @CippQueueTasks
1118

1219
$Queues = Get-AzStorageQueue -Context $StorageContext -Name ('{0}*' -f $FunctionName) | Select-Object -Property Name, ApproximateMessageCount, QueueClient
1320

@@ -19,8 +26,6 @@ function Clear-CippDurables {
1926
}
2027
}
2128

22-
Remove-AzDataTable @InstancesTable
23-
Remove-AzDataTable @HistoryTable
2429
$BlobContainer = '{0}-largemessages' -f $FunctionName
2530
if (Get-AzStorageContainer -Name $BlobContainer -Context $StorageContext -ErrorAction SilentlyContinue) {
2631
Write-Information "- Removing blob container: $BlobContainer"
@@ -29,32 +34,6 @@ function Clear-CippDurables {
2934
}
3035
}
3136

32-
$QueueTable = Get-CippTable -TableName 'CippQueue'
33-
$CippQueue = Invoke-ListCippQueue
34-
$QueueEntities = foreach ($Queue in $CippQueue) {
35-
if ($Queue.Status -eq 'Running') {
36-
$Queue.TotalTasks = $Queue.CompletedTasks
37-
$Queue | Select-Object -Property PartitionKey, RowKey, TotalTasks
38-
}
39-
}
40-
if (($QueueEntities | Measure-Object).Count -gt 0) {
41-
if ($PSCmdlet.ShouldProcess('Queues', 'Mark Failed')) {
42-
Update-AzDataTableEntity -Force @QueueTable -Entity $QueueEntities
43-
}
44-
}
45-
46-
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
47-
$RunningTasks = Get-CIPPAzDataTableEntity @CippQueueTasks -Filter "PartitionKey eq 'Task' and Status eq 'Running'" -Property RowKey, PartitionKey, Status
48-
if (($RunningTasks | Measure-Object).Count -gt 0) {
49-
if ($PSCmdlet.ShouldProcess('Tasks', 'Mark Failed')) {
50-
$UpdatedTasks = foreach ($Task in $RunningTasks) {
51-
$Task.Status = 'Failed'
52-
$Task
53-
}
54-
Update-AzDataTableEntity -Force @CippQueueTasks -Entity $UpdatedTasks
55-
}
56-
}
57-
5837
$null = Get-CippTable -TableName ('{0}History' -f $FunctionName)
5938
Write-Information 'Durable Orchestrators and Queues have been cleared'
6039
return $true

0 commit comments

Comments
 (0)