mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:41:25 +00:00
fix(cron): restore interval cadence after restart
This commit is contained in:
@@ -113,11 +113,19 @@ export function computeJobNextRunAtMs(job: CronJob, nowMs: number): number | und
|
||||
return undefined;
|
||||
}
|
||||
if (job.schedule.kind === "every") {
|
||||
const everyMs = Math.max(1, Math.floor(job.schedule.everyMs));
|
||||
const lastRunAtMs = job.state.lastRunAtMs;
|
||||
if (typeof lastRunAtMs === "number" && Number.isFinite(lastRunAtMs)) {
|
||||
const nextFromLastRun = Math.floor(lastRunAtMs) + everyMs;
|
||||
if (nextFromLastRun > nowMs) {
|
||||
return nextFromLastRun;
|
||||
}
|
||||
}
|
||||
const anchorMs = resolveEveryAnchorMs({
|
||||
schedule: job.schedule,
|
||||
fallbackAnchorMs: job.createdAtMs,
|
||||
});
|
||||
return computeNextRunAtMs({ ...job.schedule, anchorMs }, nowMs);
|
||||
return computeNextRunAtMs({ ...job.schedule, everyMs, anchorMs }, nowMs);
|
||||
}
|
||||
if (job.schedule.kind === "at") {
|
||||
// One-shot jobs stay due until they successfully finish.
|
||||
|
||||
Reference in New Issue
Block a user