fix(cron): preserve overrides and harden next-run calculation

This commit is contained in:
Peter Steinberger
2026-02-16 23:31:26 +00:00
parent 968bba5c18
commit b3d0e0cb45
3 changed files with 5 additions and 11 deletions

View File

@@ -62,13 +62,12 @@ export function computeNextRunAtMs(schedule: CronSchedule, nowMs: number): numbe
}
// Guard against same-second rescheduling loops: if croner returns
// "now" (or an earlier instant) when the job completed mid-second,
// retry from the next whole second.
// "now" (or an earlier instant), retry from the next whole second.
const nextSecondMs = Math.floor(nowMs / 1000) * 1000 + 1000;
const retry = cron.nextRun(new Date(nextSecondMs));
if (!retry) {
return undefined;
}
const retryMs = retry.getTime();
return Number.isFinite(retryMs) ? retryMs : undefined;
return Number.isFinite(retryMs) && retryMs > nowMs ? retryMs : undefined;
}