MCPcopy
hub / github.com/learnhouse/learnhouse / waitForUrl

Function waitForUrl

apps/cli/tests/helpers.ts:86–102  ·  view source on GitHub ↗
(url: string, timeoutMs = 120_000)

Source from the content-addressed store, hash-verified

84 * Requiring consecutive successes avoids returning during a brief up-blip while
85 * a freshly-installed/just-upgraded stack's nginx upstream is still flapping. */
86export async function waitForUrl(url: string, timeoutMs = 120_000): Promise<boolean> {
87 const deadline = Date.now() + timeoutMs
88 let consecutive = 0
89 while (Date.now() < deadline) {
90 try {
91 const res = await fetch(url, { signal: AbortSignal.timeout(4000) })
92 if (res.ok) {
93 if (++consecutive >= 2) return true
94 await new Promise((r) => setTimeout(r, 750)) // confirm stability quickly
95 continue
96 }
97 consecutive = 0 // a non-2xx (e.g. 502) resets the streak
98 } catch { consecutive = 0 /* not ready */ }
99 await new Promise((r) => setTimeout(r, 1500))
100 }
101 return false
102}
103
104/** Polls the org seed endpoint */
105export async function waitForOrgSeed(port: number, orgSlug = 'default', timeoutMs = 60_000): Promise<boolean> {

Callers 2

waitForOrgSeedFunction · 0.85

Calls 1

fetchFunction · 0.85

Tested by

no test coverage detected