fix(demo): stop waiting ten seconds to notice a finished build
Some checks failed
Tests / Declarative: Post Actions failed: 2, passed: 142
Some checks failed
Tests / Declarative: Post Actions failed: 2, passed: 142
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 <noreply@anthropic.com>
This commit is contained in:
parent
3946ec8eed
commit
8899b76d07
@ -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'
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user