MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / waitForService

Function waitForService

scripts/dev-with-automation.mjs:795–822  ·  view source on GitHub ↗
(name, url, timeoutMs = 30000, proc = null)

Source from the content-addressed store, hash-verified

793}
794
795async function waitForService(name, url, timeoutMs = 30000, proc = null) {
796 const start = Date.now();
797 let lastError = null;
798
799 while (Date.now() - start < timeoutMs) {
800 // A service that already exited will never answer; let the caller report
801 // the exit instead of polling until the timeout.
802 if (proc && !isProcessRunning(proc)) return false;
803 try {
804 const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
805 if (res.ok) {
806 logService(name, `Ready at ${url}`, c.green);
807 return true;
808 }
809 } catch (err) {
810 lastError = err;
811 // Keep trying
812 }
813 await delay(500);
814 }
815
816 const elapsed = Math.round((Date.now() - start) / 1000);
817 logService(name, `Timeout waiting for ${url} after ${elapsed}s`, c.red);
818 if (lastError) {
819 logService(name, `Last error: ${lastError.message}`, c.dim);
820 }
821 return false;
822}
823
824// ═══════════════════════════════════════════════════════════════════════════
825// Service Starters

Callers 2

watchAutomationStartupFunction · 0.70
mainFunction · 0.70

Calls 3

isProcessRunningFunction · 0.90
delayFunction · 0.85
logServiceFunction · 0.70

Tested by

no test coverage detected