Skip to content

Commit 0f97ce4

Browse files
committed
Make redis readiness check recoverable
1 parent cfd7c3d commit 0f97ce4

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/routes/getReady.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { Request, Response } from "express";
22
import { Server } from "http";
33
import { config } from "../config";
4-
import { getRedisActiveRequests, getRedisStats } from "../utils/redis";
4+
import { getRedisStats } from "../utils/redis";
55
import { Postgres } from "../databases/Postgres";
66
import { db } from "../databases/databases";
77

88
export async function getReady(req: Request, res: Response, server: Server): Promise<Response> {
99
const connections = await new Promise((resolve) => server.getConnections((_, count) => resolve(count))) as number;
1010

11+
const redisStats = getRedisStats();
12+
const postgresStats = (db as Postgres).getStats?.();
13+
1114
if (!connections
1215
|| (connections < config.maxConnections
13-
&& (!config.redis || getRedisActiveRequests() < config.redis.maxConnections * 0.8)
14-
&& (!config.redis || getRedisStats().avgReadTime < 2000)
15-
&& (!config.postgres || (db as Postgres).getStats().activeRequests < config.postgres.maxActiveRequests * 0.8))
16-
&& (!config.postgres || (db as Postgres).getStats().avgReadTime < 2000)) {
16+
&& (!config.redis || redisStats.activeRequests < config.redis.maxConnections * 0.8)
17+
&& (!config.redis || redisStats.avgReadTime < 2000 || redisStats.activeRequests < 1)
18+
&& (!config.postgres || postgresStats.activeRequests < config.postgres.maxActiveRequests * 0.8))
19+
&& (!config.postgres || postgresStats.avgReadTime < 2000)) {
1720
return res.sendStatus(200);
1821
} else {
1922
return res.sendStatus(500);

src/utils/redis.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,4 @@ async function setupCacheClientTracking(client: RedisClientType,
429429
await client.sendCommand(["CLIENT", "TRACKING", "ON", "REDIRECT", cacheConnectionClientId, "BCAST"]);
430430
}
431431

432-
export function getRedisActiveRequests() {
433-
return activeRequests;
434-
}
435-
436432
export default exportClient;

0 commit comments

Comments
 (0)