mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 23:06:38 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user