debug: worker stall check

This commit is contained in:
Móricz Gergő 2024-11-08 20:19:44 +01:00
parent ef505f8d99
commit 085ac3e71c
2 changed files with 15 additions and 2 deletions

View File

@ -102,6 +102,8 @@ process.on("SIGTERM", () => {
isShuttingDown = true;
});
let cantAcceptConnectionCount = 0;
const workerFun = async (
queue: Queue,
processJobInternal: (token: string, job: Job) => Promise<any>
@ -127,8 +129,19 @@ const workerFun = async (
const canAcceptConnection = await monitor.acceptConnection();
if (!canAcceptConnection) {
console.log("Cant accept connection");
cantAcceptConnectionCount++;
if (cantAcceptConnectionCount >= 25) {
logger.error("WORKER STALLED", {
cpuUsage: await monitor.checkCpuUsage(),
memoryUsage: await monitor.checkMemoryUsage(),
});
}
await sleep(cantAcceptConnectionInterval); // more sleep
continue;
} else {
cantAcceptConnectionCount = 0;
}
const job = await worker.getNextJob(token);

View File

@ -40,7 +40,7 @@ class SystemMonitor {
return SystemMonitor.instance;
}
private async checkMemoryUsage() {
public async checkMemoryUsage() {
if (IS_KUBERNETES) {
return this._checkMemoryUsageKubernetes();
}
@ -102,7 +102,7 @@ class SystemMonitor {
return usedMemoryPercentage;
}
private async checkCpuUsage() {
public async checkCpuUsage() {
if (IS_KUBERNETES) {
return this._checkCpuUsageKubernetes();
}