diff --git a/src/routes/getReady.ts b/src/routes/getReady.ts index 3c71229..02a6b0c 100644 --- a/src/routes/getReady.ts +++ b/src/routes/getReady.ts @@ -1,19 +1,22 @@ import { Request, Response } from "express"; import { Server } from "http"; import { config } from "../config"; -import { getRedisActiveRequests, getRedisStats } from "../utils/redis"; +import { getRedisStats } from "../utils/redis"; import { Postgres } from "../databases/Postgres"; import { db } from "../databases/databases"; export async function getReady(req: Request, res: Response, server: Server): Promise { const connections = await new Promise((resolve) => server.getConnections((_, count) => resolve(count))) as number; + const redisStats = getRedisStats(); + const postgresStats = (db as Postgres).getStats?.(); + if (!connections || (connections < config.maxConnections - && (!config.redis || getRedisActiveRequests() < config.redis.maxConnections * 0.8) - && (!config.redis || getRedisStats().avgReadTime < 2000) - && (!config.postgres || (db as Postgres).getStats().activeRequests < config.postgres.maxActiveRequests * 0.8)) - && (!config.postgres || (db as Postgres).getStats().avgReadTime < 2000)) { + && (!config.redis || redisStats.activeRequests < config.redis.maxConnections * 0.8) + && (!config.redis || redisStats.avgReadTime < 2000 || redisStats.activeRequests < 1) + && (!config.postgres || postgresStats.activeRequests < config.postgres.maxActiveRequests * 0.8)) + && (!config.postgres || postgresStats.avgReadTime < 2000)) { return res.sendStatus(200); } else { return res.sendStatus(500); diff --git a/src/utils/redis.ts b/src/utils/redis.ts index 5879048..e158250 100644 --- a/src/utils/redis.ts +++ b/src/utils/redis.ts @@ -429,8 +429,4 @@ async function setupCacheClientTracking(client: RedisClientType, await client.sendCommand(["CLIENT", "TRACKING", "ON", "REDIRECT", cacheConnectionClientId, "BCAST"]); } -export function getRedisActiveRequests() { - return activeRequests; -} - export default exportClient;