@@ -26,16 +26,13 @@ function Start-DurableCleanup {
2626
2727 $CleanupCount = 0
2828 $QueueCount = 0
29- $ClearQueues = $false
3029
3130 $FunctionsWithLongRunningOrchestrators = [System.Collections.Generic.List [object ]]::new()
3231 foreach ($Table in $InstancesTables ) {
33- $RunningOrchestratorCount = 0
3432 $Table = Get-CippTable - TableName $Table
3533 $FunctionName = $Table.TableName -replace ' Instances' , ' '
3634 $Orchestrators = Get-CIPPAzDataTableEntity @Table - Filter " RuntimeStatus eq 'Running'" | Select-Object * - ExcludeProperty Input
3735 $Queues = Get-AzStorageQueue - Context $StorageContext - Name (' {0}*' -f $FunctionName ) | Select-Object - Property Name, ApproximateMessageCount, QueueClient
38- $RunningOrchestratorCount = $Orchestrators.Count
3936 $LongRunningOrchestrators = $Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime }
4037 if ($LongRunningOrchestrators.Count -gt 0 ) {
4138 $FunctionsWithLongRunningOrchestrators.Add (@ {' FunctionName' = $FunctionName })
@@ -45,7 +42,6 @@ function Start-DurableCleanup {
4542 $TimeSpan = New-TimeSpan - Start $CreatedTime - End (Get-Date ).ToUniversalTime()
4643 $RunningDuration = [math ]::Round($TimeSpan.TotalMinutes , 2 )
4744 Write-Information " Orchestrator: $ ( $Orchestrator.PartitionKey ) , created: $CreatedTime , running for: $RunningDuration minutes"
48- $ClearQueues = $true
4945 if ($PSCmdlet.ShouldProcess ($_.PartitionKey , ' Terminate Orchestrator' )) {
5046 $Orchestrator = Get-CIPPAzDataTableEntity @Table - Filter " PartitionKey eq '$ ( $Orchestrator.PartitionKey ) '"
5147 $Orchestrator.RuntimeStatus = ' Failed'
@@ -58,7 +54,7 @@ function Start-DurableCleanup {
5854 $CleanupCount ++
5955 }
6056 }
61- if ($ClearQueues -or ( $RunningOrchestratorCount -eq 0 -and $Queues.ApproximateMessageCount -gt 0 ) ) {
57+ if ($LongRunningOrchestrators .Count -gt 0 -and $Queues.ApproximateMessageCount -gt 0 ) {
6258 $RunningQueues = $Queues | Where-Object { $_.ApproximateMessageCount -gt 0 }
6359 foreach ($Queue in $RunningQueues ) {
6460 Write-Information " - Removing queue: $ ( $Queue.Name ) , message count: $ ( $Queue.ApproximateMessageCount ) "
0 commit comments