Skip to content

Commit be2db2f

Browse files
committed
fix forever loading bug by not waiting for all tenants before reporting data
not fully fixed, just allows partial results on alltenant query Also add queue id for tracking problematic ones
1 parent 5064118 commit be2db2f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ListMailboxRules.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ListMailboxRules {
3+
function Invoke-ListMailboxRules {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -28,18 +28,15 @@ Function Invoke-ListMailboxRules {
2828

2929
$Metadata = @{}
3030
# If a queue is running, we will not start a new one
31-
if ($RunningQueue) {
31+
if ($RunningQueue -and !$Rows) {
3232
$Metadata = [PSCustomObject]@{
3333
QueueMessage = "Still loading data for $TenantFilter. Please check back in a few more minutes"
34+
QueueId = $RunningQueue.RowKey
3435
}
3536
[PSCustomObject]@{
3637
Waiting = $true
3738
}
3839
} elseif ((!$Rows -and !$RunningQueue) -or ($TenantFilter -eq 'AllTenants' -and ($Rows | Measure-Object).Count -eq 1)) {
39-
# If no rows are found and no queue is running, we will start a new one
40-
$Metadata = [PSCustomObject]@{
41-
QueueMessage = "Loading data for $TenantFilter. Please check back in 1 minute"
42-
}
4340

4441
if ($TenantFilter -eq 'AllTenants') {
4542
$Tenants = Get-Tenants -IncludeErrors | Select-Object defaultDomainName
@@ -49,6 +46,12 @@ Function Invoke-ListMailboxRules {
4946
$Type = $TenantFilter
5047
}
5148
$Queue = New-CippQueueEntry -Name "Mailbox Rules ($Type)" -Reference $QueueReference -TotalTasks ($Tenants | Measure-Object).Count
49+
# If no rows are found and no queue is running, we will start a new one
50+
$Metadata = [PSCustomObject]@{
51+
QueueMessage = "Loading data for $TenantFilter. Please check back in 1 minute"
52+
QueueId = $Queue.RowKey
53+
}
54+
5255
$Batch = $Tenants | Select-Object defaultDomainName, @{Name = 'FunctionName'; Expression = { 'ListMailboxRulesQueue' } }, @{Name = 'QueueName'; Expression = { $_.defaultDomainName } }, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }
5356
if (($Batch | Measure-Object).Count -gt 0) {
5457
$InputObject = [PSCustomObject]@{
@@ -66,6 +69,9 @@ Function Invoke-ListMailboxRules {
6669
$Rows = $Rows | Where-Object -Property Tenant -EQ $TenantFilter
6770
$Rows = $Rows
6871
}
72+
$Metadata = [PSCustomObject]@{
73+
QueueId = $RunningQueue.RowKey ?? $null
74+
}
6975
$GraphRequest = $Rows | ForEach-Object {
7076
$NewObj = $_.Rules | ConvertFrom-Json -ErrorAction SilentlyContinue
7177
$NewObj | Add-Member -NotePropertyName 'Tenant' -NotePropertyValue $_.Tenant -Force

0 commit comments

Comments
 (0)