Merged in fix/redis-api-model-validation (pull request #2000)

* fix: model response validation for 204
* log: add more logging when deleting keys
* add version to health endpoint


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2025-05-07 13:45:35 +00:00
parent bf7992da5b
commit 3ea26259df
5 changed files with 62 additions and 23 deletions
+29 -7
View File
@@ -1,33 +1,55 @@
import Elysia, { t } from "elysia";
import { redis } from "@/services/redis";
import { baseLogger } from "@/utils/logger";
import { baseLogger, loggerModule } from "@/utils/logger";
import { env } from "@/env";
const healthLogger = baseLogger.child({
module: "health",
});
export const healthRoutes = new Elysia().get(
"/health",
async ({ set, status }) => {
async ({ status }) => {
const perf = performance.now();
let healthy = true;
try {
await redis.ping();
} catch (e) {
baseLogger.error("Redis connection error:", e);
console.log("Redis connection error:", e);
healthLogger.error("Redis connection error:", e);
return status(503, { healthy: false });
healthy = false;
}
const duration = performance.now() - perf;
baseLogger.info(`Service healthy: ${duration.toFixed(2)} ms`);
const durationString = `${duration.toFixed(2)} ms`;
return { healthy: true };
if (!healthy) {
healthLogger.error("Health check failed");
return status(503, {
healthy,
version: env.VERSION,
duration: durationString,
});
}
return {
healthy,
version: env.VERSION,
duration: durationString,
};
},
{
response: {
200: t.Object({
healthy: t.Boolean(),
version: t.String(),
duration: t.String(),
}),
503: t.Object({
healthy: t.Boolean(),
version: t.String(),
duration: t.String(),
}),
},
}