perf(api): improve healthcheck a bit

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-20 07:49:19 +02:00
parent 25f329a4cd
commit e348a6a12c

View File

@@ -228,11 +228,15 @@ const startServer = async () => {
reply.send({ name: 'openpanel sdk api' });
});
fastify.get('/healthcheck', async (request, reply) => {
const redisRes = await withTimings(getRedisCache().keys('*'));
const redisRes = await withTimings(
getRedisCache().keys('keys op:buffer:*'),
);
const dbRes = await withTimings(db.project.findFirst());
const queueRes = await withTimings(eventsQueue.getCompleted());
const chRes = await withTimings(
chQuery(`SELECT * FROM ${TABLE_NAMES.events} LIMIT 1`),
chQuery(
`SELECT * FROM ${TABLE_NAMES.events} WHERE created_at > now() - INTERVAL 10 MINUTE LIMIT 1`,
),
);
const status = redisRes && dbRes && queueRes && chRes ? 200 : 500;