Skip to content

Commit 94663e3

Browse files
committed
fix: Update batch processing to use Timestamp for stale detection and remove unnecessary properties
1 parent 650bb8a commit 94663e3

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Webhooks/Push-AuditLogProcessingBatch.ps1

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,29 @@ function Push-AuditLogProcessingBatch {
2828

2929
do {
3030
# Fetch only the properties needed to determine claim status and build the batch
31-
$WebhookCache = Get-CIPPAzDataTableEntity @WebhookCacheTable -First $PageSize -Skip $Skip -Property @('PartitionKey', 'RowKey', 'ETag', 'CippProcessing', 'CippProcessingStarted')
31+
$WebhookCache = Get-CIPPAzDataTableEntity @WebhookCacheTable -First $PageSize -Skip $Skip -Property @('PartitionKey', 'RowKey', 'ETag', 'Timestamp', 'CippProcessing')
3232
$PageCount = $WebhookCache.Count
3333

3434
# Filter client-side: skip rows actively claimed unless the claim is stale (> 4 hours old)
3535
$TenantGroups = $WebhookCache | Where-Object {
3636
-not $_.CippProcessing -or
37-
(-not $_.CippProcessingStarted) -or
38-
([datetime]$_.CippProcessingStarted -lt $StaleThreshold)
37+
($_.Timestamp -and $_.Timestamp.UtcDateTime -lt $StaleThreshold)
3938
} | Group-Object -Property PartitionKey
4039
$WebhookCache = $null
4140

4241
if ($TenantGroups) {
43-
$ProcessingTimestamp = $NowUtc.ToString('yyyy-MM-ddTHH:mm:ssZ')
4442
foreach ($TenantGroup in $TenantGroups) {
4543
$TenantFilter = $TenantGroup.Name
4644
$Rows = @($TenantGroup.Group)
4745
$RowIds = @($Rows.RowKey)
4846

4947
# Claim these rows so subsequent timer runs skip them (UpsertMerge preserves JSON and other fields)
48+
# The entity Timestamp is updated automatically on write and used for stale detection.
5049
foreach ($Row in $Rows) {
5150
$ClaimEntity = [PSCustomObject]@{
52-
PartitionKey = $Row.PartitionKey
53-
RowKey = $Row.RowKey
54-
CippProcessing = $true
55-
CippProcessingStarted = $ProcessingTimestamp
51+
PartitionKey = $Row.PartitionKey
52+
RowKey = $Row.RowKey
53+
CippProcessing = $true
5654
}
5755
Add-CIPPAzDataTableEntity @WebhookCacheTable -Entity $ClaimEntity -OperationType UpsertMerge
5856
}

0 commit comments

Comments
 (0)