diff --git a/src/SIL.XForge.Scripture/ClientApp/e2e/await-application-startup.mts b/src/SIL.XForge.Scripture/ClientApp/e2e/await-application-startup.mts index 0b8400a9f7..4889a2d815 100755 --- a/src/SIL.XForge.Scripture/ClientApp/e2e/await-application-startup.mts +++ b/src/SIL.XForge.Scripture/ClientApp/e2e/await-application-startup.mts @@ -3,12 +3,18 @@ // This script polls to check whether the application has started at localhost:5000, and exits when it has started up, // or exits with a failure if it hasn't started in 5 minutes. -const pollUrl = 'http://localhost:5000/projects'; +const programName = "await-application-startup"; +const pollUrl = "http://localhost:5000/projects"; const pollInterval = 1000; +const quietPeriodSec = 50_000; const timeout = 5 * 60_000; +function output(message: string) { + console.log(programName + ": " + message); +} + setTimeout(() => { - console.log('Failed to start in ', timeout, ' milliseconds. Exiting.') + output(`Failed to start in ${timeout} milliseconds. Exiting.`); Deno.exit(1); }, timeout); @@ -17,24 +23,40 @@ function elapsedTime() { const currentTIme = Date.now(); const elapsed = currentTIme - startTime; const minutes = Math.floor(elapsed / 60_000); - const seconds = Math.floor((elapsed % 60_000) / 1000) - return `${minutes}:${seconds < 10 ? '0' + seconds : seconds}` + const seconds = Math.floor((elapsed % 60_000) / 1000); + return `${minutes}:${seconds < 10 ? "0" + seconds : seconds}`; } async function check() { + const elapsedSec: number = Date.now() - startTime; + const isQuietPeriod: boolean = elapsedSec < quietPeriodSec; + try { const response = await fetch(pollUrl, { - headers: { 'Accept': 'text/html' } + headers: { Accept: "text/html" } }); if (response.ok) { - console.log(elapsedTime(), 'Startup check passed. Exiting.') + if (isQuietPeriod) { + console.log(); // New line after dots + } + output(`${elapsedTime()} Startup check passed. Exiting.`); Deno.exit(0); } else { - console.log(elapsedTime(), 'Startup check failed: ', response.status, response.statusText) - } } catch (error) { - console.log(elapsedTime(), 'Startup check failed: '+ error.message) + if (isQuietPeriod) { + Deno.stdout.writeSync(new TextEncoder().encode(".")); + } else { + output(`${elapsedTime()} Startup check failed: ${response.status} ${response.statusText}`); + } + } + } catch (error) { + if (isQuietPeriod) { + Deno.stdout.writeSync(new TextEncoder().encode(".")); + return; + } + const message = error instanceof Error ? error.message : String(error); + output(`${elapsedTime()} Startup check failed: ${message}`); } } setTimeout(check, 0); -setInterval(check, pollInterval); \ No newline at end of file +setInterval(check, pollInterval);