mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 02:32:56 +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:
@@ -148,4 +148,59 @@ describe("CronService store migrations", () => {
|
||||
cron.stop();
|
||||
await store.cleanup();
|
||||
});
|
||||
|
||||
it("migrates legacy cron fields (jobId + schedule.cron) and defaults wakeMode", async () => {
|
||||
const store = await makeStorePath();
|
||||
await fs.mkdir(path.dirname(store.storePath), { recursive: true });
|
||||
await fs.writeFile(
|
||||
store.storePath,
|
||||
JSON.stringify(
|
||||
{
|
||||
version: 1,
|
||||
jobs: [
|
||||
{
|
||||
jobId: "legacy-cron-field-job",
|
||||
name: "legacy cron field",
|
||||
enabled: true,
|
||||
createdAtMs: Date.parse("2026-02-01T12:00:00.000Z"),
|
||||
updatedAtMs: Date.parse("2026-02-05T12:00:00.000Z"),
|
||||
schedule: { kind: "cron", cron: "*/5 * * * *", tz: "UTC" },
|
||||
payload: { kind: "systemEvent", text: "tick" },
|
||||
state: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const cron = await createStartedCron(store.storePath).start();
|
||||
const jobs = await cron.list({ includeDisabled: true });
|
||||
const job = jobs.find((entry) => entry.id === "legacy-cron-field-job");
|
||||
expect(job).toBeDefined();
|
||||
expect(job?.wakeMode).toBe("now");
|
||||
expect(job?.schedule.kind).toBe("cron");
|
||||
if (job?.schedule.kind === "cron") {
|
||||
expect(job.schedule.expr).toBe("*/5 * * * *");
|
||||
}
|
||||
|
||||
const persisted = JSON.parse(await fs.readFile(store.storePath, "utf-8")) as {
|
||||
jobs: Array<Record<string, unknown>>;
|
||||
};
|
||||
const persistedJob = persisted.jobs.find((entry) => entry.id === "legacy-cron-field-job");
|
||||
expect(persistedJob).toBeDefined();
|
||||
expect(persistedJob?.jobId).toBeUndefined();
|
||||
expect(persistedJob?.wakeMode).toBe("now");
|
||||
const persistedSchedule =
|
||||
persistedJob?.schedule && typeof persistedJob.schedule === "object"
|
||||
? (persistedJob.schedule as Record<string, unknown>)
|
||||
: null;
|
||||
expect(persistedSchedule?.cron).toBeUndefined();
|
||||
expect(persistedSchedule?.expr).toBe("*/5 * * * *");
|
||||
|
||||
cron.stop();
|
||||
await store.cleanup();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user