Skip to content

Commit

Permalink
Added retry capability
Browse files Browse the repository at this point in the history
  • Loading branch information
borondy authored Oct 16, 2024
1 parent c3ad03a commit 414d91f
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/internal/functions/Get-AzOpsRoleEligibilityScheduleRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,28 @@

# Process RoleEligibilitySchedule which is used to construct AzOpsRoleEligibilityScheduleRequest
Write-AzOpsMessage -LogLevel Debug -LogString 'Get-AzOpsRoleEligibilityScheduleRequest.Processing' -LogStringValues $ScopeObject.Scope -Target $ScopeObject
$roleEligibilitySchedules = Get-AzRoleEligibilitySchedule -Scope $ScopeObject.Scope -WarningAction SilentlyContinue | Where-Object {$_.Scope -eq $ScopeObject.Scope}

$roleEligibilitySchedules = Invoke-AzOpsScriptBlock -ArgumentList @($ScopeObject) -ScriptBlock {
Get-AzRoleEligibilitySchedule -Scope $ScopeObject.Scope -WarningAction SilentlyContinue -ErrorAction Stop | Where-Object { $_.Scope -eq $ScopeObject.Scope }
} -RetryCount 3 -RetryWait 5 -RetryType Exponential -ErrorAction Stop

if ($roleEligibilitySchedules) {
foreach ($roleEligibilitySchedule in $roleEligibilitySchedules) {
# Process roleEligibilitySchedule together with RoleEligibilityScheduleRequest
$roleEligibilityScheduleRequest = Get-AzRoleEligibilityScheduleRequest -Scope $ScopeObject.Scope -Name $roleEligibilitySchedule.Name -ErrorAction SilentlyContinue
if ($roleEligibilityScheduleRequest) {
Write-AzOpsMessage -LogLevel Debug -LogString 'Get-AzOpsRoleEligibilityScheduleRequest.Assignment' -LogStringValues $roleEligibilitySchedule.Name -Target $ScopeObject
# Construct AzOpsRoleEligibilityScheduleRequest by combining information from roleEligibilitySchedule and roleEligibilityScheduleRequest
[AzOpsRoleEligibilityScheduleRequest]::new($roleEligibilitySchedule, $roleEligibilityScheduleRequest)
}
$roleEligibilityScheduleRequests = Invoke-AzOpsScriptBlock -ArgumentList @($ScopeObject) -ScriptBlock {
Get-AzRoleEligibilityScheduleRequest -Scope $ScopeObject.Scope -ErrorAction Stop
} -RetryCount 3 -RetryWait 5 -RetryType Exponential -ErrorAction Stop
}

if (-not $roleEligibilityScheduleRequests) {
return
}

foreach ($roleEligibilitySchedule in $roleEligibilitySchedules) {
# Process roleEligibilitySchedule together with RoleEligibilityScheduleRequest
$roleEligibilityScheduleRequest = $roleEligibilityScheduleRequests.Where{ $_.TargetRoleEligibilityScheduleId -eq $roleEligibilitySchedule.Id }
if ($roleEligibilityScheduleRequest -and $roleEligibilityScheduleRequest.Count -eq 1) {
Write-AzOpsMessage -LogLevel Debug -LogString 'Get-AzOpsRoleEligibilityScheduleRequest.Assignment' -LogStringValues $roleEligibilitySchedule.Name -Target $ScopeObject
# Construct AzOpsRoleEligibilityScheduleRequest by combining information from roleEligibilitySchedule and roleEligibilityScheduleRequest
[AzOpsRoleEligibilityScheduleRequest]::new($roleEligibilitySchedule, $roleEligibilityScheduleRequest)
}
}
}
Expand Down

0 comments on commit 414d91f

Please sign in to comment.