From 8899b76d07cc26d966a14eb3b9666fd288196249 Mon Sep 17 00:00:00 2001 From: jenkins Date: Fri, 7 Aug 2026 01:08:24 -0300 Subject: [PATCH] fix(demo): stop waiting ten seconds to notice a finished build wait_for_build slept before its first poll, so a build that had already finished still bought a full interval of silence. On stage that reads as the script having missed the result - the build goes red in Jenkins and the terminal sits there. Polling first and sleeping after removes it entirely: a finished build now returns in under a second, measured. The interval drops from ten seconds to three for the same reason. The wait is dead air in front of an audience and a Jenkins status read is cheap. The budget is now expressed in seconds rather than poll counts, so shortening the interval does not silently shorten the timeout. This is only the script's own latency. Ariadne's autotriage cron is * * * * *, so an incident still takes up to a minute to appear after a build fails, and no amount of polling here changes that. Co-Authored-By: Claude Opus 5 --- scripts/ops/hermes_demo_lib.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/ops/hermes_demo_lib.sh b/scripts/ops/hermes_demo_lib.sh index df42864d7..468a3dfde 100644 --- a/scripts/ops/hermes_demo_lib.sh +++ b/scripts/ops/hermes_demo_lib.sh @@ -67,11 +67,17 @@ last_build_number() { python3 -c 'import json,sys; print(json.load(sys.stdin)["lastBuild"]["number"])' } -wait_for_build() { # job number [tries] -> prints result - local job="$1" num="$2" tries="${3:-120}" - for _ in $(seq 1 "$tries"); do - sleep 10 - local body result building +# Polls before sleeping, not after. Sleeping first meant a build that had +# already finished still cost a full interval of silence, which on stage reads +# as the script having missed it. The interval is short for the same reason: +# the wait is dead air in front of an audience, and a Jenkins status read is +# cheap. +BUILD_POLL_SECONDS="${BUILD_POLL_SECONDS:-3}" + +wait_for_build() { # job number [max_seconds] -> prints result + local job="$1" num="$2" budget="${3:-1500}" + local waited=0 body building result + while [ "$waited" -le "$budget" ]; do body="$(jenkins_get "/job/$job/$num/api/json?tree=result,building" || true)" building="$(printf '%s' "$body" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("building"))' 2>/dev/null || echo unknown)" @@ -80,6 +86,8 @@ wait_for_build() { # job number [tries] -> prints result printf '%s' "$result" return 0 fi + sleep "$BUILD_POLL_SECONDS" + waited=$((waited + BUILD_POLL_SECONDS)) done printf 'TIMEOUT' }