mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 03:55:05 +00:00
fix: stagger missed cron jobs on restart (#18925) (thanks @rexlunae)
This commit is contained in:
committed by
Vincent Koc
parent
41a39085d3
commit
3c4377651e
@@ -2,9 +2,9 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { CronService } from "./service.js";
|
||||
import { createCronServiceState } from "./state.js";
|
||||
import { setupCronServiceSuite } from "./service.test-harness.js";
|
||||
import { runMissedJobs } from "./timer.js";
|
||||
import { createCronServiceState } from "./service/state.js";
|
||||
import { runMissedJobs } from "./service/timer.js";
|
||||
|
||||
const { logger: noopLogger, makeStorePath } = setupCronServiceSuite({
|
||||
prefix: "openclaw-cron-",
|
||||
@@ -406,8 +406,9 @@ describe("CronService restart catch-up", () => {
|
||||
expect(staggeredJobs[1]?.state.nextRunAtMs).toBeGreaterThan(
|
||||
staggeredJobs[0]?.state.nextRunAtMs ?? 0,
|
||||
);
|
||||
expect((staggeredJobs[1]?.state.nextRunAtMs ?? 0) - (staggeredJobs[0]?.state.nextRunAtMs ?? 0))
|
||||
.toBe(5_000);
|
||||
expect(
|
||||
(staggeredJobs[1]?.state.nextRunAtMs ?? 0) - (staggeredJobs[0]?.state.nextRunAtMs ?? 0),
|
||||
).toBe(5_000);
|
||||
|
||||
await store.cleanup();
|
||||
});
|
||||
|
||||
@@ -858,7 +858,9 @@ export async function runMissedJobs(
|
||||
startupCandidates: [] as Array<{ jobId: string; job: CronJob }>,
|
||||
};
|
||||
}
|
||||
const sorted = missed.toSorted((a, b) => (a.state.nextRunAtMs ?? 0) - (b.state.nextRunAtMs ?? 0));
|
||||
const sorted = missed.toSorted(
|
||||
(a, b) => (a.state.nextRunAtMs ?? 0) - (b.state.nextRunAtMs ?? 0),
|
||||
);
|
||||
const startupCandidates = sorted.slice(0, maxImmediate);
|
||||
const deferred = sorted.slice(maxImmediate);
|
||||
if (deferred.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user