Add priority preemption to BuildIngestionService - #17
Merged
Conversation
When priority builds arrive via PrioritizeBuild(), cancel in-flight non-priority tasks to free worker slots immediately. This prevents priority builds from starving behind long-running normal ingestion. Key changes: - Configurable max parallelism via constructor (for testability) - Per-task CancellationTokenSource linked to the global CTS - Priority signal (SemaphoreSlim) wakes worker loop on PrioritizeBuild - PreemptNonPriorityTasks cancels non-priority CTSes, drains them - WaitOrCancel<T> extension races tasks against cancellation token - Preempted tasks reset to pending (no attempt increment) - AzdoClient.Create(HttpMessageHandler) factory for test injection Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes priority queue starvation where navigating to the builds menu would queue priority builds that had to wait behind already-running normal builds.
Changes
Priority preemption mechanism:
PrioritizeBuild()is called, in-flight non-priority tasks are cancelled via per-taskCancellationTokenSourcependingstate (no attempt increment) so they'll be retriedTask.WhenAnywith aSemaphoreSlimpriority signal to detect incoming priority workCancellation safety (compile-time guarantees):
InsertTestsData,InsertTimelineData,InsertPrInfoData,MarkComplete,MarkFailed, etc.) are static local functions that structurally cannot capture theCancellationTokenFetchTestsDataAsync,FetchTimelineDataAsync,FetchPrInfoDataAsync) are static and explicitly receiveCancellationTokenCancellationTokenthreaded throughAzdoClientandHelixClientHTTP calls for proper cooperative cancellationTesting infrastructure:
DelegateHandlerpattern forHttpMessageHandlerinjection (no subclassing per test)AzdoClient.Create(HttpMessageHandler)andHelixClient.Create(HttpMessageHandler)factoriesMaxParallelismconfigurable via constructor for deterministic test controlpendingstateTest results
All 174 tests pass, 0 warnings.