fix: stabilize cron log wait
This commit is contained in:
@@ -53,14 +53,15 @@ async function waitForCronFinished(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function waitForNonEmptyFile(pathname: string, timeoutMs = 2000) {
|
async function waitForNonEmptyFile(pathname: string, timeoutMs = 2000) {
|
||||||
const deadline = Date.now() + timeoutMs;
|
const startedAt = process.hrtime.bigint();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const raw = await fs.readFile(pathname, "utf-8").catch(() => "");
|
const raw = await fs.readFile(pathname, "utf-8").catch(() => "");
|
||||||
if (raw.trim().length > 0) return raw;
|
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}`);
|
throw new Error(`timeout waiting for file ${pathname}`);
|
||||||
}
|
}
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
await yieldToEventLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user