//#region src/utils/healthChecks.ts
const HEALTH_CHECK_TIMEOUT_MS = 5e3;
async function withTimeout(promise, timeoutMs) {
	let timeoutId;
	const timeoutPromise = new Promise((_, reject) => {
		timeoutId = setTimeout(() => {
			reject(/* @__PURE__ */ new Error(`Health check timed out after ${timeoutMs}ms`));
		}, timeoutMs);
	});
	try {
		return await Promise.race([promise, timeoutPromise]);
	} finally {
		if (timeoutId !== void 0) clearTimeout(timeoutId);
	}
}
async function checkManageDb(pool) {
	try {
		await withTimeout(pool.query("SELECT 1"), HEALTH_CHECK_TIMEOUT_MS);
		return true;
	} catch {
		return false;
	}
}
async function checkRunDb(client) {
	try {
		if ("$client" in client && client.$client) {
			const pool = client.$client;
			await withTimeout(pool.query("SELECT 1"), HEALTH_CHECK_TIMEOUT_MS);
			return true;
		}
		return false;
	} catch {
		return false;
	}
}

//#endregion
export { checkManageDb, checkRunDb };