Skip to content

Commit acc1dba

Browse files
push db cache
1 parent 9846930 commit acc1dba

File tree

5 files changed

+12
-84
lines changed

5 files changed

+12
-84
lines changed

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-CIPPDBCacheData.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Push-CIPPDBCacheData {
1111
#>
1212
[CmdletBinding()]
1313
param($Item)
14-
14+
Write-Host "Starting cache collection for tenant: $($Item.TenantFilter) - Queue: $($Item.QueueName) (ID: $($Item.QueueId))"
1515
$TenantFilter = $Item.TenantFilter
1616
#This collects all data for a tenant and caches it in the CIPP Reporting database. DO NOT ADD PROCESSING OR LOGIC HERE.
1717
#The point of this file is to always be <10 minutes execution time.

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tests/Invoke-CIPPTestsRun.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Invoke-CIPPTestsRun {
2525

2626
Write-Information "Found $($AllTests.Count) test functions to run"
2727
$AllTenantsList = if ($TenantFilter -eq 'allTenants') {
28-
$DbCounts = Get-CIPPDbItem -CountsOnly
28+
$DbCounts = Get-CIPPDbItem -CountsOnly -TenantFilter 'allTenants'
2929
$TenantsWithData = $DbCounts | Where-Object { $_.Count -gt 0 } | Select-Object -ExpandProperty PartitionKey -Unique
3030
Write-Information "Found $($TenantsWithData.Count) tenants with data in database"
3131
$TenantsWithData

Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-CIPPDBCacheOrchestrator.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function Start-CIPPDBCacheOrchestrator {
1414

1515
try {
1616
Write-LogMessage -API 'CIPPDBCache' -message 'Starting database cache orchestration' -sev Info
17-
17+
Write-Host 'Starting database cache orchestration'
1818
$TenantList = Get-Tenants | Where-Object { $_.defaultDomainName -ne $null }
1919

2020
if ($TenantList.Count -eq 0) {
@@ -23,7 +23,6 @@ function Start-CIPPDBCacheOrchestrator {
2323
}
2424

2525
$Queue = New-CippQueueEntry -Name 'Database Cache Collection' -TotalTasks $TenantList.Count
26-
2726
$Batch = foreach ($Tenant in $TenantList) {
2827
[PSCustomObject]@{
2928
FunctionName = 'Push-CIPPDBCacheData'
@@ -32,7 +31,8 @@ function Start-CIPPDBCacheOrchestrator {
3231
QueueName = "DB Cache - $($Tenant.defaultDomainName)"
3332
}
3433
}
35-
34+
Write-Host "Created queue $($Queue.RowKey) for database cache collection of $($TenantList.Count) tenants"
35+
Write-Host "Starting batch of $($Batch.Count) cache collection activities"
3636
$InputObject = [PSCustomObject]@{
3737
Batch = @($Batch)
3838
OrchestratorName = 'CIPPDBCacheOrchestrator'

Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-DurableCleanup.ps1

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,81 +17,5 @@ function Start-DurableCleanup {
1717
param(
1818
[int]$MaxDuration = 86400
1919
)
20-
21-
$WarningPreference = 'SilentlyContinue'
22-
$StorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage
23-
$TargetTime = (Get-Date).ToUniversalTime().AddSeconds(-$MaxDuration)
24-
$Context = New-AzDataTableContext -ConnectionString $env:AzureWebJobsStorage
25-
$InstancesTables = Get-AzDataTable -Context $Context | Where-Object { $_ -match 'Instances' }
26-
27-
$CleanupCount = 0
28-
$QueueCount = 0
29-
30-
$FunctionsWithLongRunningOrchestrators = [System.Collections.Generic.List[object]]::new()
31-
$NonDeterministicOrchestrators = [System.Collections.Generic.List[object]]::new()
32-
33-
foreach ($Table in $InstancesTables) {
34-
$Table = Get-CippTable -TableName $Table
35-
$FunctionName = $Table.TableName -replace 'Instances', ''
36-
$Orchestrators = Get-CIPPAzDataTableEntity @Table -Filter "RuntimeStatus eq 'Running'" | Select-Object * -ExcludeProperty Input
37-
$Queues = Get-AzStorageQueue -Context $StorageContext -Name ('{0}*' -f $FunctionName) | Select-Object -Property Name, ApproximateMessageCount, QueueClient
38-
$LongRunningOrchestrators = $Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime }
39-
40-
if ($LongRunningOrchestrators.Count -gt 0) {
41-
$FunctionsWithLongRunningOrchestrators.Add(@{'FunctionName' = $FunctionName })
42-
foreach ($Orchestrator in $LongRunningOrchestrators) {
43-
$CreatedTime = [DateTime]::SpecifyKind($Orchestrator.CreatedTime.DateTime, [DateTimeKind]::Utc)
44-
$TimeSpan = New-TimeSpan -Start $CreatedTime -End (Get-Date).ToUniversalTime()
45-
$RunningDuration = [math]::Round($TimeSpan.TotalMinutes, 2)
46-
Write-Information "Orchestrator: $($Orchestrator.PartitionKey), created: $CreatedTime, running for: $RunningDuration minutes"
47-
if ($PSCmdlet.ShouldProcess($_.PartitionKey, 'Terminate Orchestrator')) {
48-
$Orchestrator = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq '$($Orchestrator.PartitionKey)'"
49-
$Orchestrator.RuntimeStatus = 'Failed'
50-
if ($Orchestrator.PSObject.Properties.Name -contains 'CustomStatus') {
51-
$Orchestrator.CustomStatus = "Terminated by Durable Cleanup - Exceeded max duration of $MaxDuration seconds"
52-
} else {
53-
$Orchestrator | Add-Member -MemberType NoteProperty -Name CustomStatus -Value "Terminated by Durable Cleanup - Exceeded max duration of $MaxDuration seconds"
54-
}
55-
Update-AzDataTableEntity @Table -Entity $Orchestrator
56-
$CleanupCount++
57-
}
58-
}
59-
}
60-
61-
$NonDeterministicOrchestrators = $Orchestrators | Where-Object { $_.Output -match 'Non-Deterministic workflow detected' }
62-
if ($NonDeterministicOrchestrators.Count -gt 0) {
63-
$NonDeterministicOrchestrators.Add(@{'FunctionName' = $FunctionName })
64-
foreach ($Orchestrator in $NonDeterministicOrchestrators) {
65-
Write-Information "Orchestrator: $($Orchestrator.PartitionKey) is Non-Deterministic"
66-
if ($PSCmdlet.ShouldProcess($_.PartitionKey, 'Terminate Orchestrator')) {
67-
$Orchestrator = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq '$($Orchestrator.PartitionKey)'"
68-
$Orchestrator.RuntimeStatus = 'Failed'
69-
if ($Orchestrator.PSObject.Properties.Name -contains 'CustomStatus') {
70-
$Orchestrator.CustomStatus = 'Terminated by Durable Cleanup - Non-Deterministic workflow detected'
71-
} else {
72-
$Orchestrator | Add-Member -MemberType NoteProperty -Name CustomStatus -Value 'Terminated by Durable Cleanup - Non-Deterministic workflow detected'
73-
}
74-
Update-AzDataTableEntity @Table -Entity $Orchestrator
75-
$CleanupCount++
76-
}
77-
}
78-
}
79-
80-
if (($LongRunningOrchestrators.Count -gt 0 -or $NonDeterministicOrchestrators.Count -gt 0) -and $Queues.ApproximateMessageCount -gt 0) {
81-
$RunningQueues = $Queues | Where-Object { $_.ApproximateMessageCount -gt 0 }
82-
foreach ($Queue in $RunningQueues) {
83-
Write-Information "- Removing queue: $($Queue.Name), message count: $($Queue.ApproximateMessageCount)"
84-
if ($PSCmdlet.ShouldProcess($Queue.Name, 'Clear Queue')) {
85-
$Queue.QueueClient.ClearMessagesAsync() | Out-Null
86-
}
87-
$QueueCount++
88-
}
89-
}
90-
}
91-
92-
if ($CleanupCount -gt 0 -or $QueueCount -gt 0) {
93-
Write-LogMessage -api 'Durable Cleanup' -message "$CleanupCount orchestrators were terminated. $QueueCount queues were cleared." -sev 'Info' -LogData $FunctionsWithLongRunningOrchestrators
94-
}
95-
96-
Write-Information "Durable cleanup complete. $CleanupCount orchestrators were terminated. $QueueCount queues were cleared."
20+
Write-Information "This cleanup is no longer required."
9721
}

Modules/CIPPCore/Public/Get-CIPPDbItem.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Get-CIPPDbItem {
2323
#>
2424
[CmdletBinding()]
2525
param(
26-
[Parameter(Mandatory = $true)]
26+
[Parameter(Mandatory = $false)]
2727
[string]$TenantFilter,
2828

2929
[Parameter(Mandatory = $false)]
@@ -37,7 +37,11 @@ function Get-CIPPDbItem {
3737
$Table = Get-CippTable -tablename 'CippReportingDB'
3838

3939
if ($CountsOnly) {
40-
$Filter = "PartitionKey eq '{0}'" -f $TenantFilter
40+
if ($TenantFilter -eq 'allTenants') {
41+
$Filter = $null
42+
} else {
43+
$Filter = "PartitionKey eq '{0}'" -f $TenantFilter
44+
}
4145
$Results = Get-CIPPAzDataTableEntity @Table -Filter $Filter
4246
$Results = $Results | Where-Object { $_.RowKey -like '*-Count' }
4347
} else {

0 commit comments

Comments
 (0)