fix(cron): migrate legacy schedule cron fields on load (#28889)

Backfill legacy jobs that still use schedule.cron and jobId so upgraded instances keep firing existing cron schedules instead of failing silently.

Closes #28861
This commit is contained in:
Sid
2026-03-01 20:53:39 +08:00
committed by GitHub
parent d509a81a12
commit 504c1f3607
6 changed files with 147 additions and 6 deletions

View File

@@ -25,6 +25,9 @@ function coerceSchedule(schedule: UnknownRecord) {
const next: UnknownRecord = { ...schedule };
const rawKind = typeof schedule.kind === "string" ? schedule.kind.trim().toLowerCase() : "";
const kind = rawKind === "at" || rawKind === "every" || rawKind === "cron" ? rawKind : undefined;
const exprRaw = typeof schedule.expr === "string" ? schedule.expr.trim() : "";
const legacyCronRaw = typeof schedule.cron === "string" ? schedule.cron.trim() : "";
const normalizedExpr = exprRaw || legacyCronRaw;
const atMsRaw = schedule.atMs;
const atRaw = schedule.at;
const atString = typeof atRaw === "string" ? atRaw.trim() : "";
@@ -48,7 +51,7 @@ function coerceSchedule(schedule: UnknownRecord) {
next.kind = "at";
} else if (typeof schedule.everyMs === "number") {
next.kind = "every";
} else if (typeof schedule.expr === "string") {
} else if (normalizedExpr) {
next.kind = "cron";
}
}
@@ -62,6 +65,15 @@ function coerceSchedule(schedule: UnknownRecord) {
delete next.atMs;
}
if (normalizedExpr) {
next.expr = normalizedExpr;
} else if ("expr" in next) {
delete next.expr;
}
if ("cron" in next) {
delete next.cron;
}
const staggerMs = normalizeCronStaggerMs(schedule.staggerMs);
if (staggerMs !== undefined) {
next.staggerMs = staggerMs;