Skip to content

Commit 44ae2fd

Browse files
committed
chore(deadcode): remove obsolete cron execution wrapper
1 parent 8e76feb commit 44ae2fd

3 files changed

Lines changed: 11 additions & 57 deletions

File tree

src/cron/active-jobs-manual-run.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Regression: upstream commit 7d1575b5df (#60310, 2026-04-04) introduced
22
// activeJobIds + markCronJobActive/clearCronJobActive but only wired the pair
3-
// into runDueJob and executeJob. The manual-run path (cron.run() →
3+
// into the scheduled due-job path. The manual-run path (cron.run() →
44
// prepareManualRun + finishPreparedManualRun in src/cron/service/ops.ts) was
55
// left without the mark/clear pair, so task-registry.maintenance.ts
66
// hasBackingSession (cron branch under isRuntimeAuthoritative()=true)

src/cron/service/timer.regression.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import { createCronServiceState, type CronEvent } from "./state.js";
4343
import {
4444
DEFAULT_JOB_TIMEOUT_MS,
4545
applyJobResult,
46-
executeJob,
4746
executeJobCore,
4847
executeJobCoreWithTimeout,
4948
onTimer,
@@ -1738,6 +1737,7 @@ describe("cron service timer regressions", () => {
17381737
});
17391738

17401739
it("retries recurring wake-now main jobs until temporary lane pressure clears (#75964)", async () => {
1740+
const store = timerRegressionFixtures.makeStorePath();
17411741
let now = 0;
17421742
const nowMs = () => {
17431743
now += 10;
@@ -1759,11 +1759,11 @@ describe("cron service timer regressions", () => {
17591759
sessionTarget: "main",
17601760
wakeMode: "now",
17611761
payload: { kind: "systemEvent", text: "tick" },
1762-
state: { nextRunAtMs: 0 },
1762+
state: { nextRunAtMs: 1 },
17631763
};
17641764
const state = createCronServiceState({
17651765
cronEnabled: true,
1766-
storePath: "/tmp/openclaw-cron-busy-main-test/jobs.json",
1766+
storePath: store.storePath,
17671767
log: noopLogger,
17681768
nowMs,
17691769
enqueueSystemEvent,
@@ -1774,16 +1774,20 @@ describe("cron service timer regressions", () => {
17741774
runIsolatedAgentJob: createDefaultIsolatedRunner(),
17751775
});
17761776
state.store = { version: 1, jobs: [job] };
1777+
await saveCronStore(store.storePath, { version: 1, jobs: [job] });
17771778

1778-
const runPromise = executeJob(state, job, nowMs(), { forced: false });
1779+
const runPromise = runMissedJobs(state);
17791780
await vi.advanceTimersByTimeAsync(1);
17801781
await runPromise;
17811782

1783+
const persistedJob = (await loadCronStore(store.storePath)).jobs.find(
1784+
(candidate) => candidate.id === job.id,
1785+
);
17821786
expect(enqueueSystemEvent).toHaveBeenCalledTimes(1);
17831787
expect(runHeartbeatOnce).toHaveBeenCalledTimes(2);
17841788
expect(requestHeartbeat).not.toHaveBeenCalled();
1785-
expect(job.state.lastStatus).toBe("ok");
1786-
expect(job.state.runningAtMs).toBeUndefined();
1789+
expect(persistedJob?.state.lastStatus).toBe("ok");
1790+
expect(persistedJob?.state.runningAtMs).toBeUndefined();
17871791
});
17881792

17891793
it("retries cron schedule computation from the next second when the first attempt returns undefined (#17821)", () => {

src/cron/service/timer.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,56 +2164,6 @@ async function executeDetachedCronJob(
21642164
};
21652165
}
21662166

2167-
/** Executes a cron job and applies the resulting state transitions in memory. */
2168-
export async function executeJob(
2169-
state: CronServiceState,
2170-
job: CronJob,
2171-
_nowMs: number,
2172-
_opts: { forced: boolean },
2173-
) {
2174-
if (!job.state) {
2175-
job.state = {};
2176-
}
2177-
const startedAt = state.deps.nowMs();
2178-
job.state.runningAtMs = startedAt;
2179-
job.state.lastError = undefined;
2180-
const activeJobMarker = markCronJobActive(job.id, {
2181-
preserveAcrossGenerationAdvance: job.sessionTarget === "main",
2182-
});
2183-
emit(state, { jobId: job.id, action: "started", job, runAtMs: startedAt });
2184-
2185-
let coreResult: {
2186-
status: CronRunStatus;
2187-
delivered?: boolean;
2188-
delivery?: CronDeliveryTrace;
2189-
} & CronRunOutcome &
2190-
CronRunTelemetry;
2191-
try {
2192-
coreResult = await executeJobCoreWithTimeout(state, job, { activeJobMarker });
2193-
} catch (err) {
2194-
coreResult = { status: "error", error: String(err) };
2195-
}
2196-
2197-
const endedAt = state.deps.nowMs();
2198-
const shouldDelete = applyJobResult(state, job, {
2199-
status: coreResult.status,
2200-
error: coreResult.error,
2201-
diagnostics: coreResult.diagnostics,
2202-
delivered: coreResult.delivered,
2203-
provider: coreResult.provider,
2204-
startedAt,
2205-
endedAt,
2206-
});
2207-
2208-
emitJobFinished(state, job, coreResult, startedAt);
2209-
2210-
if (shouldDelete && state.store) {
2211-
state.store.jobs = state.store.jobs.filter((j) => j.id !== job.id);
2212-
emit(state, { jobId: job.id, action: "removed", job });
2213-
}
2214-
clearCronJobActive(job.id, activeJobMarker);
2215-
}
2216-
22172167
function emitJobFinished(
22182168
state: CronServiceState,
22192169
job: CronJob,

0 commit comments

Comments
 (0)