mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 23:20:22 +00:00
fix(cron): preserve manual timeoutSeconds on add
This commit is contained in:
@@ -1,5 +1,29 @@
|
||||
import { normalizeLegacyDeliveryInput } from "../legacy-delivery.js";
|
||||
import type { CronDelivery, CronJobCreate } from "../types.js";
|
||||
|
||||
export function normalizeCronCreateDeliveryInput(input: CronJobCreate): CronJobCreate {
|
||||
const payloadRecord =
|
||||
input.payload && typeof input.payload === "object"
|
||||
? ({ ...input.payload } as Record<string, unknown>)
|
||||
: null;
|
||||
const deliveryRecord =
|
||||
input.delivery && typeof input.delivery === "object"
|
||||
? ({ ...input.delivery } as Record<string, unknown>)
|
||||
: null;
|
||||
const normalizedLegacy = normalizeLegacyDeliveryInput({
|
||||
delivery: deliveryRecord,
|
||||
payload: payloadRecord,
|
||||
});
|
||||
if (!normalizedLegacy.mutated) {
|
||||
return input;
|
||||
}
|
||||
return {
|
||||
...input,
|
||||
payload: payloadRecord ? (payloadRecord as typeof input.payload) : input.payload,
|
||||
delivery: (normalizedLegacy.delivery as CronDelivery | undefined) ?? input.delivery,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveInitialCronDelivery(input: CronJobCreate): CronDelivery | undefined {
|
||||
if (input.delivery) {
|
||||
return input.delivery;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { normalizeCronJobCreate } from "../normalize.js";
|
||||
import type { CronJob, CronJobCreate, CronJobPatch } from "../types.js";
|
||||
import { normalizeCronCreateDeliveryInput } from "./initial-delivery.js";
|
||||
import {
|
||||
applyJobPatch,
|
||||
computeJobNextRunAtMs,
|
||||
@@ -235,10 +235,7 @@ export async function add(state: CronServiceState, input: CronJobCreate) {
|
||||
return await locked(state, async () => {
|
||||
warnIfDisabled(state, "add");
|
||||
await ensureLoaded(state);
|
||||
const normalizedInput = normalizeCronJobCreate(input);
|
||||
if (!normalizedInput) {
|
||||
throw new Error("invalid cron job input");
|
||||
}
|
||||
const normalizedInput = normalizeCronCreateDeliveryInput(input);
|
||||
const job = createJob(state, normalizedInput);
|
||||
state.store?.jobs.push(job);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user