31 lines
754 B
TypeScript
31 lines
754 B
TypeScript
/**
|
|
* Simple liveness & readiness helpers
|
|
*/
|
|
|
|
export type ReadinessResult = {
|
|
ok: boolean;
|
|
details: { name: string; ok: boolean; error?: string }[];
|
|
};
|
|
|
|
export function liveness() {
|
|
return {
|
|
status: 'ok',
|
|
timestamp: Date.now(),
|
|
};
|
|
}
|
|
|
|
export async function readiness(
|
|
checks: Array<{ name: string; fn: () => Promise<boolean> | boolean }>
|
|
): Promise<ReadinessResult> {
|
|
const results: ReadinessResult['details'] = [];
|
|
for (const c of checks) {
|
|
try {
|
|
const r = await Promise.resolve(c.fn());
|
|
results.push({ name: c.name, ok: !!r });
|
|
} catch (err: any) {
|
|
results.push({ name: c.name, ok: false, error: err?.message ?? String(err) });
|
|
}
|
|
}
|
|
return { ok: results.every((r) => r.ok), details: results };
|
|
}
|