docs: document cron schedule helpers · openclaw/openclaw@31ce6df
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Builds stable identities for cron scheduling inputs. */ |
1 | 2 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
2 | 3 | import { coerceFiniteScheduleNumber } from "./schedule-number.js"; |
3 | 4 | import { normalizeCronStaggerMs } from "./stagger.js"; |
@@ -34,6 +35,8 @@ function schedulePayloadFromRecord(
|
34 | 35 | const tz = readString(schedule, "tz"); |
35 | 36 | const staggerMs = readStaggerMs(schedule); |
36 | 37 | const kind = |
| 38 | +// Infer legacy shorthand schedule shapes when kind is missing so timer |
| 39 | +// identity remains stable across old persisted jobs and normalized jobs. |
37 | 40 | rawKind === "at" || rawKind === "every" || rawKind === "cron" |
38 | 41 | ? rawKind |
39 | 42 | : at |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Coerces cron schedule number fields with strict finite-number parsing. */ |
1 | 2 | import { parseStrictFiniteNumber } from "@openclaw/normalization-core/number-coercion"; |
2 | 3 | |
3 | 4 | /** Coerces schedule numeric fields without accepting partial or non-finite numbers. */ |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Computes at/every/cron schedule timestamps with bounded Croner caching. */ |
1 | 2 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
2 | 3 | import { Cron } from "croner"; |
3 | 4 | import { parseAbsoluteTimeMs } from "./parse.js"; |
@@ -27,6 +28,8 @@ function resolveCachedCron(expr: string, timezone: string): Cron {
|
27 | 28 | return cached; |
28 | 29 | } |
29 | 30 | if (cronEvalCache.size >= CRON_EVAL_CACHE_MAX) { |
| 31 | +// Expression parsing is expensive enough to cache, but cron jobs can be |
| 32 | +// edited dynamically; keep the cache bounded and LRU-like. |
30 | 33 | const oldest = cronEvalCache.keys().next().value; |
31 | 34 | if (oldest) { |
32 | 35 | cronEvalCache.delete(oldest); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Timeout watchdogs for isolated cron agent setup and execution phases. */ |
1 | 2 | import type { |
2 | 3 | CronAgentExecutionPhase, |
3 | 4 | CronAgentExecutionPhaseUpdate, |
@@ -111,6 +112,8 @@ export function createCronAgentWatchdog(params: {
|
111 | 112 | const previousPhase = activeExecution?.phase; |
112 | 113 | activeExecution = { ...activeExecution, ...info }; |
113 | 114 | const stage = info.phase ? CRON_AGENT_PHASE_WATCHDOG_STAGE[info.phase] : undefined; |
| 115 | +// A fallback attempt can return to setup-like phases after execution began; |
| 116 | +// re-arm pre-execution timing so the fallback path cannot stall silently. |
114 | 117 | if ( |
115 | 118 | state === "executing" && |
116 | 119 | previousPhase === "before_agent_reply" && |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Formats stable cron timeout and execution error messages. */ |
1 | 2 | import { formatEmbeddedAgentExecutionPhase } from "../../agents/embedded-agent-runner/execution-phase.js"; |
2 | 3 | import type { CronAgentExecutionStarted } from "../types.js"; |
3 | 4 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Resolves and emits cron failure-alert notifications. */ |
1 | 2 | import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce"; |
2 | 3 | import { resolveFailoverReasonFromError } from "../../agents/failover-error.js"; |
3 | 4 | import type { CronFailureNotificationDelivery, CronJob, CronMessageChannel } from "../types.js"; |
@@ -78,6 +79,8 @@ export function resolveFailureAlert(
|
78 | 79 | const mode = jobConfig?.mode ?? globalConfig?.mode; |
79 | 80 | const explicitTo = normalizeTo(jobConfig?.to); |
80 | 81 | |
| 82 | +// Announce alerts inherit the job delivery target; webhook alerts require an |
| 83 | +// explicit alert target so chat recipients are not reused as URLs. |
81 | 84 | return { |
82 | 85 | after: clampPositiveInt(jobConfig?.after ?? globalConfig?.after, DEFAULT_FAILURE_ALERT_AFTER), |
83 | 86 | cooldownMs: clampNonNegativeInt( |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Resolves create-time default delivery for new cron jobs. */ |
1 | 2 | import type { CronDelivery, CronJobCreate } from "../types.js"; |
2 | 3 | |
3 | 4 | /** Resolves default cron delivery for new jobs when callers omit explicit delivery config. */ |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Cron job scheduling, validation, creation, and patch helpers. */ |
1 | 2 | import crypto from "node:crypto"; |
2 | 3 | import { |
3 | 4 | normalizeOptionalString, |
@@ -343,6 +344,7 @@ function assertDeliverySupport(job: Pick<CronJob, "sessionTarget" | "delivery">)
|
343 | 344 | return; |
344 | 345 | } |
345 | 346 | if (job.delivery.mode === "webhook") { |
| 347 | +// Webhook delivery is standalone and does not need an isolated chat target. |
346 | 348 | return; |
347 | 349 | } |
348 | 350 | const isIsolatedLike = |
@@ -844,6 +846,8 @@ export function applyJobPatch(
|
844 | 846 | ); |
845 | 847 | } |
846 | 848 | if (job.sessionTarget === "main" && job.delivery?.mode !== "webhook") { |
| 849 | +// Main-session jobs cannot auto-announce; keep only an empty failure |
| 850 | +// destination object when the patch is clearing nested fields. |
847 | 851 | const failureDestination = job.delivery?.failureDestination; |
848 | 852 | job.delivery = |
849 | 853 | failureDestination && !hasConcreteFailureDestination(failureDestination) |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。