Skip to content

Commit

Permalink
Filter out fugure purge dates resources
Browse files Browse the repository at this point in the history
  • Loading branch information
weshaggard committed Aug 13, 2021
1 parent 58608fc commit 413e69f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions eng/scripts/live-test-resource-cleanup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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

0 comments on commit 413e69f

Please sign in to comment.