MCPcopy
hub / github.com/vectorize-io/hindsight / waitForReady

Method waitForReady

hindsight-all-npm/src/server.ts:300–321  ·  view source on GitHub ↗

Poll `/health` until it succeeds or `readyTimeoutMs` elapses.

()

Source from the content-addressed store, hash-verified

298
299 /** Poll `/health` until it succeeds or `readyTimeoutMs` elapses. */
300 private async waitForReady(): Promise<void> {
301 const deadline = Date.now() + this.readyTimeoutMs;
302 let attempt = 0;
303 while (Date.now() < deadline) {
304 attempt++;
305 try {
306 const res = await fetch(`${this.baseUrl}/health`, {
307 signal: AbortSignal.timeout(this.readyPollIntervalMs),
308 });
309 if (res.ok) {
310 this.logger.debug(`[hindsight] health check passed (attempt ${attempt})`);
311 return;
312 }
313 } catch {
314 // expected while the daemon is still booting
315 }
316 await new Promise((resolve) => setTimeout(resolve, this.readyPollIntervalMs));
317 }
318 throw new Error(
319 `Hindsight daemon did not become ready within ${this.readyTimeoutMs}ms at ${this.baseUrl}`
320 );
321 }
322}

Callers 4

startMethod · 0.95
index.test.tsFile · 0.80
index.tsFile · 0.80
runRetainFunction · 0.80

Calls 2

debugMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected