chore: scan count config

This commit is contained in:
Bas950
2024-09-17 10:54:48 +02:00
parent d24eda8957
commit 09bcfe703f

View File

@@ -1,3 +1,4 @@
import process from "node:process";
import pLimit from "p-limit";
import { mainLog, redis } from "../index.js";
import { activePresenceGauge } from "../tracing.js";
@@ -6,6 +7,8 @@ import { insertIpData } from "./insertIpData.js";
export const updateActivePresenceGaugeLimit = pLimit(1);
let log: debug.Debugger | undefined;
const scanCount = Number.parseInt(process.env.SCAN_COUNT || "1000", 10);
export async function updateActivePresenceGauge() {
await updateActivePresenceGaugeLimit(async () => {
log ??= mainLog.extend("Heartbeat-Updates");
@@ -20,7 +23,7 @@ export async function updateActivePresenceGauge() {
}>();
do {
const [newCursor, keys] = await redis.scan(cursor, "MATCH", pattern, "COUNT", 1000);
const [newCursor, keys] = await redis.scan(cursor, "MATCH", pattern, "COUNT", scanCount);
cursor = newCursor;
//* Use pipelining for batch Redis operations