quality / commitlint (push) Skipped
CD / update-wiki (push) Successful in 8s
quality / changes (push) Successful in 8s
quality / web (push) Skipped
quality / docker-check (push) Skipped
quality / api (push) Successful in 1m20s
CD / quality (push) Successful in 1m31s
CD / publish (push) Successful in 2m4s
Co-authored-by: Cursor <[email protected]>
18 lines
599 B
TypeScript
18 lines
599 B
TypeScript
import type { LbIpRow } from "./types.js";
|
|
import { isPoolMember } from "./health.js";
|
|
|
|
export function failoverDesired(rows: LbIpRow[]): string[] {
|
|
if (rows.length === 0) return [];
|
|
const live = rows.filter((r) => isPoolMember(r.health));
|
|
const pool = live.length > 0 ? live : rows;
|
|
const sorted = [...pool].sort(
|
|
(a, b) => a.priority - b.priority || a.weight - b.weight,
|
|
);
|
|
const minPriority = sorted[0]!.priority;
|
|
const primaries = sorted.filter((r) => r.priority === minPriority);
|
|
if (live.length > 0) {
|
|
return primaries.map((r) => r.ip);
|
|
}
|
|
return [sorted[0]!.ip];
|
|
}
|