@@ -486,6 +486,41 @@ function Receive-CIPPTimerTrigger {
486486 param ($Timer )
487487
488488 $UtcNow = (Get-Date ).ToUniversalTime()
489+
490+ try {
491+ # temporary orphan check - Remove at next release.
492+ $OrphanConfigTable = Get-CIPPTable - tablename ' Config'
493+ $OrphanFlag = Get-CIPPAzDataTableEntity @OrphanConfigTable - Filter " PartitionKey eq 'OrphanRequeue' and RowKey eq 'OrphanRequeue'" - ErrorAction SilentlyContinue
494+ if (-not $OrphanFlag -or $OrphanFlag.state -ne $true ) {
495+ $OrchestratorTable = Get-CIPPTable - TableName ' CippOrchestratorInput'
496+ $OrphanedInputs = Get-CIPPAzDataTableEntity @OrchestratorTable - Filter " PartitionKey eq 'Input'"
497+ $CutoffTime = $UtcNow.AddMinutes (-5 )
498+ $StaleOrphans = @ ($OrphanedInputs | Where-Object { $_.Timestamp.DateTime -lt $CutoffTime })
499+ if ($StaleOrphans.Count -gt 0 ) {
500+ Write-Information " Found $ ( $StaleOrphans.Count ) orphaned orchestration inputs, re-queuing..."
501+ foreach ($Orphan in $StaleOrphans ) {
502+ try {
503+ Add-CippQueueMessage - Cmdlet ' Start-CIPPOrchestrator' - Parameters @ { InputObjectGuid = $Orphan.RowKey }
504+ Write-Information " Re-queued orphaned orchestration: $ ( $Orphan.RowKey ) "
505+ } catch {
506+ Write-Warning " Failed to re-queue orphan $ ( $Orphan.RowKey ) : $ ( $_.Exception.Message ) "
507+ }
508+ }
509+ Write-LogMessage - API ' TimerFunction' - message " Re-queued $ ( $StaleOrphans.Count ) orphaned orchestration inputs" - sev Info
510+ }
511+ # Mark as completed so we don't scan again
512+ $null = Add-CIPPAzDataTableEntity @OrphanConfigTable - Entity @ {
513+ PartitionKey = ' OrphanRequeue'
514+ RowKey = ' OrphanRequeue'
515+ state = $true
516+ Timestamp = $UtcNow
517+ Count = $StaleOrphans.Count
518+ } - Force
519+ }
520+ } catch {
521+ Write-Warning " Orphan re-queue check failed: $ ( $_.Exception.Message ) "
522+ }
523+
489524 $Functions = Get-CIPPTimerFunctions
490525 $Table = Get-CIPPTable - tablename CIPPTimers
491526 $Statuses = Get-CIPPAzDataTableEntity @Table
0 commit comments