From 6a49169a441b34be8097e8589b488263a4f704ff Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Fri, 13 Aug 2021 16:53:07 -0700 Subject: [PATCH] Filter out future purge dates resources --- eng/scripts/live-test-resource-cleanup.ps1 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/eng/scripts/live-test-resource-cleanup.ps1 b/eng/scripts/live-test-resource-cleanup.ps1 index 5013b6b1b8a..8f3c7763ca2 100644 --- a/eng/scripts/live-test-resource-cleanup.ps1 +++ b/eng/scripts/live-test-resource-cleanup.ps1 @@ -67,8 +67,7 @@ Write-Host "Count $($hasDeleteAfter.Count)" $toDelete = $hasDeleteAfter.Where({ $deleteDate = ($_.Tags.DeleteAfter -as [DateTime]); (!$deleteDate -or $now -gt $deleteDate) }) Write-Host "Groups to delete: $($toDelete.Count)" -# Get purgeable resources already in a deleted state coerced into a collection even if empty. -$purgeableResources = Get-PurgeableResources +$purgeableResources = @() foreach ($rg in $toDelete) { @@ -86,6 +85,16 @@ foreach ($rg in $toDelete) } } +# Get purgeable resources already in a deleted state coerced into a collection even if empty. +$purgeableResources = Get-PurgeableResources +$allPurgeCount = $purgeableResources.Count + +# Filter down to the ones that we can actually perge. +$purgeableResources = $purgeableResources.Where({ $purgeDate = $_.ScheduledPurgeDate -as [DateTime]; (!$purgeDate -or $now -gt $purgeDate) }) + # Purge all the purgeable resources. -Write-Host "Deleting $($purgeableResources.Count) purgeable resources" +Write-Host "Attempting to purge $($purgeableResources.Count) resources." +if ($allPurgeCount -gt $purgeableResources.Count) { + Write-Host "Skipping $($allPurgeCount - $purgeableResources.Count) as their purge date is still in the future." +} Remove-PurgeableResources $purgeableResources