fix: prioritize source discovery before long closeout
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
// SPEC: PJ2026-01060703 CI/CD branch follower controller scheduling.
|
||||
// Responsibility: keep automatic closeout observations ahead of unrelated followers.
|
||||
// Responsibility: keep source discovery and active closeout ahead of unrelated followers.
|
||||
|
||||
import type { FollowerSpec, FollowerState, ParsedOptions } from "./cicd-types";
|
||||
|
||||
const CLOSEOUT_PHASES = new Set(["Triggering", "ClosingOut"]);
|
||||
const ACTIVE_PHASES = new Set(["PendingTrigger", "Triggering", "Superseded"]);
|
||||
const CLOSEOUT_PHASES = new Set(["ClosingOut"]);
|
||||
const SOURCE_DISCOVERY_PHASES = new Set(["Observed", "Noop", "Succeeded", "Failed", "Blocked", "Skipped"]);
|
||||
|
||||
export function orderFollowersForControllerCloseout(
|
||||
followers: FollowerSpec[],
|
||||
@@ -21,14 +23,19 @@ export function shouldYieldAfterAutomaticTrigger(options: ParsedOptions, state:
|
||||
}
|
||||
|
||||
function followerPriority(state: Record<string, unknown> | undefined): number {
|
||||
if (state === undefined) return 2;
|
||||
if (state === undefined) return 1;
|
||||
const phase = typeof state.phase === "string" ? state.phase : null;
|
||||
if (hasStoredSourceTargetMismatch(state)) return 0;
|
||||
if (hasUnfinishedObservedSource(state)) return 0;
|
||||
if (phase !== null && CLOSEOUT_PHASES.has(phase)) return 0;
|
||||
if (typeof state.inFlightJob === "string" && state.inFlightJob.trim() !== "") return 0;
|
||||
if (phase === "PendingTrigger" || phase === "Superseded") return 1;
|
||||
return 2;
|
||||
if (phase !== null && ACTIVE_PHASES.has(phase)) return 0;
|
||||
if (isSourceDiscoveryCandidate(phase)) return 1;
|
||||
if (hasStoredSourceTargetMismatch(state)) return 2;
|
||||
if (hasUnfinishedObservedSource(state)) return 2;
|
||||
if (phase !== null && CLOSEOUT_PHASES.has(phase)) return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
function isSourceDiscoveryCandidate(phase: string | null): boolean {
|
||||
return phase === null || SOURCE_DISCOVERY_PHASES.has(phase);
|
||||
}
|
||||
|
||||
function hasStoredSourceTargetMismatch(state: Record<string, unknown>): boolean {
|
||||
|
||||
Reference in New Issue
Block a user