update: implement dynamic loop delay for spawner cycles

This commit is contained in:
ZareMate 2026-03-15 14:54:24 +01:00
parent 721eb439e7
commit 31af5dd592

View File

@ -9,7 +9,8 @@ require("dotenv").config();
const logs = [];
const MAX_LOGS = 200;
const LOOP_DELAY_MS = 60_000;
const LOOP_DELAY_MIN_MS = 5 * 60_000;
const LOOP_DELAY_MAX_MS = 10 * 60_000;
const MAX_ALLOWED_MOVE_BLOCKS = 10;
const LOOP_RESUME_TOLERANCE_BLOCKS = 1.5;
const REJOIN_DELAY_MS = 60_000;
@ -427,6 +428,11 @@ function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function getRandomLoopDelayMs() {
const span = LOOP_DELAY_MAX_MS - LOOP_DELAY_MIN_MS;
return LOOP_DELAY_MIN_MS + Math.floor(Math.random() * (span + 1));
}
function stopSpawnerLoop(reason, options = {}) {
if (!spawnerLoopRunning) return;
spawnerLoopRunning = false;
@ -1208,8 +1214,10 @@ function startSpawnerLoop() {
}
if (!spawnerLoopRunning) break;
pushLog("waiting 60s for next cycle");
await sleep(LOOP_DELAY_MS);
const waitMs = getRandomLoopDelayMs();
const waitMinutes = (waitMs / 60_000).toFixed(2);
pushLog(`waiting ${waitMinutes} min for next cycle`);
await sleep(waitMs);
}
})();
}