fix: stabilize cron log wait

This commit is contained in:
Peter Steinberger
2026-01-23 07:10:59 +00:00
parent 551685351f
commit e8352c8d21

View File

@@ -53,14 +53,15 @@ async function waitForCronFinished(
}
async function waitForNonEmptyFile(pathname: string, timeoutMs = 2000) {
const deadline = Date.now() + timeoutMs;
const startedAt = process.hrtime.bigint();
for (;;) {
const raw = await fs.readFile(pathname, "utf-8").catch(() => "");
if (raw.trim().length > 0) return raw;
if (Date.now() >= deadline) {
const elapsedMs = Number(process.hrtime.bigint() - startedAt) / 1e6;
if (elapsedMs >= timeoutMs) {
throw new Error(`timeout waiting for file ${pathname}`);
}
await new Promise((resolve) => setTimeout(resolve, 10));
await yieldToEventLoop();
}
}