mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 11:36:58 +03:00
Improve ready check
This commit is contained in:
@@ -1,11 +1,18 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { Server } from "http";
|
import { Server } from "http";
|
||||||
import { config } from "../config";
|
import { config } from "../config";
|
||||||
|
import { getRedisActiveRequests } from "../utils/redis";
|
||||||
|
import { Postgres } from "../databases/Postgres";
|
||||||
|
import { db } from "../databases/databases";
|
||||||
|
|
||||||
export async function getReady(req: Request, res: Response, server: Server): Promise<Response> {
|
export async function getReady(req: Request, res: Response, server: Server): Promise<Response> {
|
||||||
const connections = await new Promise((resolve) => server.getConnections((_, count) => resolve(count))) as number;
|
const connections = await new Promise((resolve) => server.getConnections((_, count) => resolve(count))) as number;
|
||||||
|
|
||||||
if (!connections || connections < config.maxConnections) {
|
if (!connections
|
||||||
|
|| (connections < config.maxConnections
|
||||||
|
&& (!config.redis || getRedisActiveRequests() < config.redis.maxConnections * 0.8)
|
||||||
|
&& (!config.postgres || (db as Postgres).getStats().activeRequests < config.postgres.maxActiveRequests * 0.8))
|
||||||
|
&& (!config.postgres || (db as Postgres).getStats().avgReadTime < 5000)) {
|
||||||
return res.sendStatus(200);
|
return res.sendStatus(200);
|
||||||
} else {
|
} else {
|
||||||
return res.sendStatus(500);
|
return res.sendStatus(500);
|
||||||
|
|||||||
@@ -429,4 +429,8 @@ async function setupCacheClientTracking(client: RedisClientType,
|
|||||||
await client.sendCommand(["CLIENT", "TRACKING", "ON", "REDIRECT", cacheConnectionClientId, "BCAST"]);
|
await client.sendCommand(["CLIENT", "TRACKING", "ON", "REDIRECT", cacheConnectionClientId, "BCAST"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRedisActiveRequests() {
|
||||||
|
return activeRequests;
|
||||||
|
}
|
||||||
|
|
||||||
export default exportClient;
|
export default exportClient;
|
||||||
|
|||||||
Reference in New Issue
Block a user