fix: use readiness endpoint for health checks instead of port check
The waitForHealth function now checks /api/readiness which returns 503 until background initialization completes, rather than just checking if the port is in use. This ensures callers wait for full worker readiness. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -61,7 +61,14 @@ async function isPortInUse(port: number): Promise<boolean> {
|
|||||||
async function waitForHealth(port: number, timeoutMs: number = 30000): Promise<boolean> {
|
async function waitForHealth(port: number, timeoutMs: number = 30000): Promise<boolean> {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
while (Date.now() - start < timeoutMs) {
|
while (Date.now() - start < timeoutMs) {
|
||||||
if (await isPortInUse(port)) return true;
|
try {
|
||||||
|
const response = await fetch(`http://127.0.0.1:${port}/api/readiness`, {
|
||||||
|
signal: AbortSignal.timeout(2000)
|
||||||
|
});
|
||||||
|
if (response.ok) return true;
|
||||||
|
} catch {
|
||||||
|
// Not ready yet
|
||||||
|
}
|
||||||
await new Promise(r => setTimeout(r, 500));
|
await new Promise(r => setTimeout(r, 500));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user