Download src/openwork/runtime-probes.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/openwork/runtime-probes.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/openwork/runtime-probes.js
-
curl -L -o runtime-probes.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/openwork/runtime-probes.js
1.55 kB
| // ์ค๋ช ๋ฌธ์: docs/specs/bada-code-quality.md (v1.0.0) | |
| // ํฌํธ/ํฌ์ค ๊ฒ์ฌ๋ ์ฌ์๋์ ์ทจ์ ์ ์์ผ์ ํ์ํ๋ค. | |
| const net = require('net'); | |
| const http = require('http'); | |
| async function isPortListening(port) { | |
| if (!port) return false; | |
| return new Promise((resolve) => { | |
| const socket = net.createConnection({ port: Number(port), host: '127.0.0.1' }, () => { | |
| socket.destroy(); | |
| resolve(true); | |
| }); | |
| socket.on('error', () => resolve(false)); | |
| socket.setTimeout(400, () => { | |
| socket.destroy(); | |
| resolve(false); | |
| }); | |
| }); | |
| } | |
| async function probeHealth(port, timeoutMs = 12000, signal) { | |
| const started = Date.now(); | |
| while (Date.now() - started < timeoutMs && !signal?.aborted) { | |
| try { | |
| const ok = await new Promise((resolve) => { | |
| const req = http.get(`http://127.0.0.1:${port}/health`, { timeout: 1500, signal }, (res) => { | |
| res.resume(); // ์๋ต ๋ณธ๋ฌธ์ ์๋นํด ์์ผ์ ๋ฐํํ๋ค. | |
| if (res.statusCode === 200) { | |
| resolve(true); | |
| } else { | |
| resolve(false); | |
| } | |
| }); | |
| req.on('error', () => resolve(false)); | |
| req.on('timeout', () => { req.destroy(); resolve(false); }); | |
| }); | |
| if (ok) return true; | |
| } catch (err) { | |
| // retry | |
| } | |
| await require('timers/promises').setTimeout(400, undefined, { signal }).catch(() => {}); | |
| } | |
| return false; | |
| } | |
| module.exports = { isPortListening, probeHealth }; | |