@@ -26,16 +26,13 @@ function Start-DurableCleanup {
26
26
27
27
$CleanupCount = 0
28
28
$QueueCount = 0
29
- $ClearQueues = $false
30
29
31
30
$FunctionsWithLongRunningOrchestrators = [System.Collections.Generic.List [object ]]::new()
32
31
foreach ($Table in $InstancesTables ) {
33
- $RunningOrchestratorCount = 0
34
32
$Table = Get-CippTable - TableName $Table
35
33
$FunctionName = $Table.TableName -replace ' Instances' , ' '
36
34
$Orchestrators = Get-CIPPAzDataTableEntity @Table - Filter " RuntimeStatus eq 'Running'" | Select-Object * - ExcludeProperty Input
37
35
$Queues = Get-AzStorageQueue - Context $StorageContext - Name (' {0}*' -f $FunctionName ) | Select-Object - Property Name, ApproximateMessageCount, QueueClient
38
- $RunningOrchestratorCount = $Orchestrators.Count
39
36
$LongRunningOrchestrators = $Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime }
40
37
if ($LongRunningOrchestrators.Count -gt 0 ) {
41
38
$FunctionsWithLongRunningOrchestrators.Add (@ {' FunctionName' = $FunctionName })
@@ -45,7 +42,6 @@ function Start-DurableCleanup {
45
42
$TimeSpan = New-TimeSpan - Start $CreatedTime - End (Get-Date ).ToUniversalTime()
46
43
$RunningDuration = [math ]::Round($TimeSpan.TotalMinutes , 2 )
47
44
Write-Information " Orchestrator: $ ( $Orchestrator.PartitionKey ) , created: $CreatedTime , running for: $RunningDuration minutes"
48
- $ClearQueues = $true
49
45
if ($PSCmdlet.ShouldProcess ($_.PartitionKey , ' Terminate Orchestrator' )) {
50
46
$Orchestrator = Get-CIPPAzDataTableEntity @Table - Filter " PartitionKey eq '$ ( $Orchestrator.PartitionKey ) '"
51
47
$Orchestrator.RuntimeStatus = ' Failed'
@@ -58,7 +54,7 @@ function Start-DurableCleanup {
58
54
$CleanupCount ++
59
55
}
60
56
}
61
- if ($ClearQueues -or ( $RunningOrchestratorCount -eq 0 -and $Queues.ApproximateMessageCount -gt 0 ) ) {
57
+ if ($LongRunningOrchestrators .Count -gt 0 -and $Queues.ApproximateMessageCount -gt 0 ) {
62
58
$RunningQueues = $Queues | Where-Object { $_.ApproximateMessageCount -gt 0 }
63
59
foreach ($Queue in $RunningQueues ) {
64
60
Write-Information " - Removing queue: $ ( $Queue.Name ) , message count: $ ( $Queue.ApproximateMessageCount ) "
0 commit comments