gamble.ts: print summary of runs so far before exit upon ctrl-c (#21296)

### What does this PR do?

lets you get useful info out of this script even if you set the number
of attempts too high and you don't want to wait

### How did you verify your code works?

local testing

(I cancelled CI because this script is not used anywhere in CI so it
wouldn't tell us anything useful)
This commit is contained in:
190n
2025-07-25 17:46:34 -07:00
committed by GitHub
parent 1ab76610cf
commit 2f0ddf3018

View File

@@ -29,6 +29,27 @@ const formatTime = (ms: number): string => {
const start = Date.now(); const start = Date.now();
let totalTimeEstimate = -1; let totalTimeEstimate = -1;
function report() {
process.stdout.write("\n");
const attemptsReached =
numOk + numTimedOut + signals.values().reduce((a, b) => a + b, 0) + codes.values().reduce((a, b) => a + b, 0);
green(`${pad(numOk)}/${attemptsReached} OK`);
if (numTimedOut > 0) {
red(`${pad(numTimedOut)}/${attemptsReached} timeout`);
}
for (const [signal, count] of signals.entries()) {
red(`${pad(count)}/${attemptsReached} ${signal}`);
}
for (const [code, count] of codes.entries()) {
red(`${pad(count)}/${attemptsReached} code ${code}`);
}
process.exit(numOk === attemptsReached ? 0 : 1);
}
process.on("SIGINT", report);
for (let i = 0; i < attempts; i++) { for (let i = 0; i < attempts; i++) {
const proc = Bun.spawn({ const proc = Bun.spawn({
cmd: argv, cmd: argv,
@@ -75,17 +96,5 @@ for (let i = 0; i < attempts; i++) {
const remaining = totalTimeEstimate - (now - start); const remaining = totalTimeEstimate - (now - start);
process.stdout.write(`\r\x1b[2K${pad(i + 1)}/${attempts} completed, ${formatTime(remaining)} remaining`); process.stdout.write(`\r\x1b[2K${pad(i + 1)}/${attempts} completed, ${formatTime(remaining)} remaining`);
} }
process.stdout.write("\n");
green(`${pad(numOk)}/${attempts} OK`); report();
if (numTimedOut > 0) {
red(`${pad(numTimedOut)}/${attempts} timeout`);
}
for (const [signal, count] of signals.entries()) {
red(`${pad(count)}/${attempts} ${signal}`);
}
for (const [code, count] of codes.entries()) {
red(`${pad(count)}/${attempts} code ${code}`);
}
process.exit(numOk === attempts ? 0 : 1);