feat(cron): set default enabled state for cron jobs

- Added logic to default the `enabled` property to `true` if not explicitly set as a boolean in the cron job input.
- Updated job creation and store functions to ensure consistent handling of the `enabled` state across the application.
- Enhanced input normalization to improve job configuration reliability.

This update ensures that cron jobs are enabled by default, enhancing user experience and reducing potential misconfigurations.
This commit is contained in:
Tyler Yust
2026-02-03 16:55:27 -08:00
committed by Peter Steinberger
parent 3f82daefd8
commit 1409943863
3 changed files with 10 additions and 1 deletions

View File

@@ -206,6 +206,9 @@ export function normalizeCronJobInput(
if (!next.wakeMode) {
next.wakeMode = "next-heartbeat";
}
if (typeof next.enabled !== "boolean") {
next.enabled = true;
}
if (!next.sessionTarget && isRecord(next.payload)) {
const kind = typeof next.payload.kind === "string" ? next.payload.kind : "";
if (kind === "systemEvent") {

View File

@@ -105,12 +105,13 @@ export function createJob(state: CronServiceState, input: CronJobCreate): CronJo
: input.schedule.kind === "at"
? true
: undefined;
const enabled = typeof input.enabled === "boolean" ? input.enabled : true;
const job: CronJob = {
id,
agentId: normalizeOptionalAgentId(input.agentId),
name: normalizeRequiredName(input.name),
description: normalizeOptionalText(input.description),
enabled: input.enabled,
enabled,
deleteAfterRun,
createdAtMs: now,
updatedAtMs: now,

View File

@@ -101,6 +101,11 @@ export async function ensureLoaded(state: CronServiceState) {
mutated = true;
}
if (typeof raw.enabled !== "boolean") {
raw.enabled = true;
mutated = true;
}
const payload = raw.payload;
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
if (migrateLegacyCronPayload(payload as Record<string, unknown>)) {