fix: speed up native branch follower refresh

This commit is contained in:
Codex
2026-07-03 14:21:39 +00:00
parent 7751cc167b
commit f3fccb8f35
8 changed files with 99 additions and 40 deletions
+10 -3
View File
@@ -4,7 +4,8 @@ import https from "node:https";
const namespace = process.env.NAMESPACE || "";
const pipelineRun = process.env.PIPELINERUN || "";
const shouldWait = process.env.WAIT === "true";
const timeoutSeconds = Number(process.env.TIMEOUT_SECONDS || "60");
const timeoutSeconds = requiredPositiveNumber("TIMEOUT_SECONDS");
const pollIntervalSeconds = requiredPositiveNumber("POLL_INTERVAL_SECONDS");
const host = process.env.KUBERNETES_SERVICE_HOST;
const port = Number(process.env.KUBERNETES_SERVICE_PORT || "443");
const token = readFileSync("/var/run/secrets/kubernetes.io/serviceaccount/token", "utf8").trim();
@@ -89,7 +90,7 @@ if (latest.found) {
latest = await getPipelineRun();
}
const deadline = Date.now() + Math.max(1, timeoutSeconds) * 1000;
const deadline = Date.now() + timeoutSeconds * 1000;
let polls = 0;
while (shouldWait) {
const condition = succeededCondition(latest.object);
@@ -97,7 +98,7 @@ while (shouldWait) {
if (Date.now() >= deadline) break;
polls += 1;
process.stderr.write(JSON.stringify({ event: "cicd.branch-follower.native-tekton.wait", pipelineRun, namespace, polls, conditionStatus: condition?.status || null, valuesRedacted: true }) + "\n");
await delay(2000);
await delay(pollIntervalSeconds * 1000);
latest = await getPipelineRun();
}
@@ -125,3 +126,9 @@ const output = {
};
process.stdout.write(JSON.stringify(output));
if (failed) process.exit(1);
function requiredPositiveNumber(name) {
const value = Number(process.env[name]);
if (!Number.isFinite(value) || value <= 0) throw new Error(`${name} must be a positive number`);
return value;
}