@@ -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