Skip to content

Commit faaaf43

Browse files
authored
Merge pull request sublime247#1387 from dominiccreates/standardize-mock-assertions
feat: add readiness endpoint with dependency verification to ingest-node
2 parents 7bc7061 + 5140da2 commit faaaf43

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

ingest-node/src/index.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,39 @@ app.get("/metrics", async (_req, reply) => {
448448
return reply.send(await register.metrics());
449449
});
450450

451+
// ---------------------------------------------------------------------------
452+
// Readiness endpoint – verifies underlying message queues before reporting ready
453+
// ---------------------------------------------------------------------------
454+
455+
async function checkDependencies(): Promise<boolean> {
456+
// Verify Redis connection if enabled
457+
if (REDIS_ENABLED && redisPool) {
458+
try {
459+
await redisPool.executeCommand(async (client) => client.ping());
460+
} catch (err) {
461+
console.error('[ready] Redis ping failed', err);
462+
return false;
463+
}
464+
}
465+
// Verify NATS connection if enabled
466+
if (NATS_ENABLED && nats) {
467+
if (nats.isClosed()) {
468+
console.error('[ready] NATS connection closed');
469+
return false;
470+
}
471+
}
472+
return true;
473+
}
474+
475+
app.get("/ready", async (_req, reply) => {
476+
const healthy = await checkDependencies();
477+
if (healthy) {
478+
return reply.status(200).send({ status: "ready" });
479+
} else {
480+
return reply.status(503).send({ status: "unavailable" });
481+
}
482+
});
483+
451484
// ---------------------------------------------------------------------------
452485
// Boot
453486
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)