MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / probe

Function probe

apps/cloud/scripts/dev-db.ts:186–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

184const WATCHDOG_MAX_RESTARTS = 3;
185
186const probe = async (): Promise<void> => {
187 const sql = postgres(`postgres://postgres:postgres@127.0.0.1:${PORT}/postgres`, {
188 max: 1,
189 idle_timeout: 0,
190 connect_timeout: 5,
191 fetch_types: false,
192 prepare: false,
193 onnotice: () => undefined,
194 });
195 try {
196 // connect_timeout only bounds the handshake; race the query too so a
197 // post-startup wedge cannot hang the watchdog itself.
198 await Promise.race([
199 sql.unsafe("select 1"),
200 sleep(10_000).then(() => {
201 throw new Error("probe query timed out after 10s");
202 }),
203 ]);
204 } finally {
205 await sql.end({ timeout: 5 }).catch(() => {});
206 }
207};
208
209const watchdog = async () => {
210 let consecutiveFailures = 0;

Callers 1

watchdogFunction · 0.70

Calls 3

unsafeMethod · 0.80
endMethod · 0.80
sleepFunction · 0.50

Tested by

no test coverage detected