mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:54:32 +00:00
fix(cron): keep manual runs non-blocking
This commit is contained in:
@@ -162,6 +162,59 @@ describe("CronService read ops while job is running", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps list and status responsive during manual cron.run execution", async () => {
|
||||
const store = await makeStorePath();
|
||||
const enqueueSystemEvent = vi.fn();
|
||||
const requestHeartbeatNow = vi.fn();
|
||||
const isolatedRun = createDeferredIsolatedRun();
|
||||
|
||||
const cron = new CronService({
|
||||
storePath: store.storePath,
|
||||
cronEnabled: true,
|
||||
log: noopLogger,
|
||||
enqueueSystemEvent,
|
||||
requestHeartbeatNow,
|
||||
runIsolatedAgentJob: isolatedRun.runIsolatedAgentJob,
|
||||
});
|
||||
|
||||
try {
|
||||
await cron.start();
|
||||
const job = await cron.add({
|
||||
name: "manual run isolation",
|
||||
enabled: true,
|
||||
deleteAfterRun: false,
|
||||
schedule: {
|
||||
kind: "at",
|
||||
at: new Date("2030-01-01T00:00:00.000Z").toISOString(),
|
||||
},
|
||||
sessionTarget: "isolated",
|
||||
wakeMode: "next-heartbeat",
|
||||
payload: { kind: "agentTurn", message: "manual run" },
|
||||
delivery: { mode: "none" },
|
||||
});
|
||||
|
||||
const runPromise = cron.run(job.id, "force");
|
||||
await isolatedRun.runStarted;
|
||||
|
||||
await expect(
|
||||
withTimeout(cron.list({ includeDisabled: true }), 300, "cron.list during cron.run"),
|
||||
).resolves.toBeTypeOf("object");
|
||||
await expect(withTimeout(cron.status(), 300, "cron.status during cron.run")).resolves.toEqual(
|
||||
expect.objectContaining({ enabled: true, storePath: store.storePath }),
|
||||
);
|
||||
|
||||
isolatedRun.completeRun({ status: "ok", summary: "manual done" });
|
||||
await expect(runPromise).resolves.toEqual({ ok: true, ran: true });
|
||||
|
||||
const completed = await cron.list({ includeDisabled: true });
|
||||
expect(completed[0]?.state.lastStatus).toBe("ok");
|
||||
expect(completed[0]?.state.runningAtMs).toBeUndefined();
|
||||
} finally {
|
||||
cron.stop();
|
||||
await store.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps list and status responsive during startup catch-up runs", async () => {
|
||||
const store = await makeStorePath();
|
||||
const enqueueSystemEvent = vi.fn();
|
||||
|
||||
Reference in New Issue
Block a user