Skip to main content

Cron API Reference

Everything exported from the root of @vef-framework-react/cron, grouped as in the source: permissions, API hooks, page helpers, components, and types. The two page components and their props are covered in the Overview.

QueryFunction<TData, TParams> / MutationFunction<TData, TParams> are the framework's keyed function shapes from @vef-framework-react/core; PaginatedQueryParams<TSearch> is the ProTable query shape from @vef-framework-react/components; ApiResult<T> is the standard response envelope.

Permissions

CRON_PERMISSIONS

const — permission codes for the durable cron store management API, mirroring the backend RequiredPermission strings verbatim. All schedule mutations (create / update / delete / pause / resume / trigger_now) share the single manage code — there are no per-action codes. See Permissions.

Group.keyCodeGates
schedule.querycron.schedule.querySchedule list, detail, job-name list, fire preview
schedule.managecron.schedule.manageCreate, update (incl. rename), delete, pause, resume, trigger now
run.querycron.run.queryRun journal list and single-run fetch

Type exports: CronPermissions (typeof CRON_PERMISSIONS), SchedulePermissionCodes (CronPermissions["schedule"]), RunPermissionCodes (CronPermissions["run"]).

API hooks

Query plumbing

ExportSignatureDescription
API_PATHconst "/api"The framework RPC endpoint every management call posts to.
splitQueryParams<TSearch extends AnyObject>(queryParams: PaginatedQueryParams<TSearch>) => { params: Omit<PaginatedQueryParams<TSearch>, typeof SYMBOL_PAGINATION>; pagination: PaginationParams | undefined }Splits ProTable's symbol-keyed query params into plain search params and pagination metadata. The sort symbol stays on params; JSON serialization drops it.

useScheduleApi

() => ScheduleApi — the query and mutation functions for the durable schedule store (sys/cron/schedule). Addressing is by name (there is no id-keyed delete and no batch delete), and every mutation shares the single cron.schedule.manage permission on the backend.

FunctionTypeOperation
findPageQueryFunction<PaginationResult<Schedule>, PaginatedQueryParams<ScheduleSearch>>find_page — converts the framework select's isEnabled toggle string ("true" / "false") into the real boolean the wire eq filter expects (dropped when unset)
getQueryFunction<ScheduleDetail, ScheduleNameParams>get — the schedule plus a preview of its next fire times
listJobsQueryFunction<string[]>list_jobs — the job names registered on the answering node (the only legal jobName values)
previewFiresQueryFunction<PreviewFiresResult, PreviewFiresParams>preview_fires — validated exactly like a save, so an invalid expression comes back as a business error
createMutationFunction<ApiResult<unknown>, ScheduleParams>create
updateMutationFunction<ApiResult<unknown>, ScheduleParams>update — an optional newName renames
removeMutationFunction<ApiResult<unknown>, ScheduleNameParams>delete — sends { name }
pauseMutationFunction<ApiResult<unknown>, ScheduleNameParams>pause
resumeMutationFunction<ApiResult<unknown>, ScheduleNameParams>resume
triggerNowMutationFunction<ApiResult<unknown>, ScheduleNameParams>trigger_now — one execution through the normal claim flow

useRunApi

() => RunApi — read-only query functions for the run journal (sys/cron/run). The detail view refetches the full row through find_one so it always shows the complete, untruncated error text.

FunctionTypeOperation
findPageQueryFunction<PaginationResult<Run>, PaginatedQueryParams<RunSearch>>find_page
findOneQueryFunction<Run, RunIdParams>find_one

Page helpers and form model

Exported so hosts can rebuild or extend the schedule form with identical semantics.

ScheduleFormValues

The schedule form's values. The trigger is held in the editor's value+unit shape, the timeout as a value+unit pair, and params as raw JSON text — all collapsed to the API model on submit. originalName is the addressing name captured when editing, so a changed name becomes a rename (newName).

FieldTypeDescription
idstring?Row id (present when editing).
originalNamestring?The addressing name captured when editing.
namestringUnique schedule name; editing it renames.
jobNamestringThe registered job handler.
triggerTriggerFormValuesThe trigger in editor shape.
startsAt / endsAtstringEffective window (empty = unbounded on that side).
misfirePolicyMisfirePolicyfire_now / skip.
concurrencyPolicyConcurrencyPolicyforbid / allow.
recoverbooleanRe-fire after a node crash (idempotent handlers only).
timeoutValue / timeoutUnitnumber / stringPer-run timeout as value+unit (0 = global default).
paramsTextstringThe params JSON text.
enabledbooleanEnabled state.

Form model functions

ExportSignatureDescription
SCHEDULE_FORM_DEFAULTSconst ScheduleFormValuesDefaults for a newly created schedule (cron trigger, fire_now, forbid, no recovery, zero timeout, enabled).
scheduleToFormValues(row: Schedule) => ScheduleFormValuesProjects a saved schedule into editable form values (splitting timeoutMs / everyMs into the most readable value+unit).
scheduleToParams(values: ScheduleFormValues) => ScheduleParamsConverts form values into API params: addresses by originalName, renames via newName, collapses the trigger, timeout and params.
parseJsonParams(text: string) => JsonParamsResultParses the params textarea into a JSON object. Empty text is valid and omits the params entirely; anything that is not a JSON object is rejected.
jsonParamsError(text: string) => string | undefinedThe field-validator form of parseJsonParams: an error message when invalid, undefined when valid.
JsonParamsResult{ ok: true; value?: JsonObject } | { ok: false; error: string }The outcome of parsing the params textarea.
TIMEOUT_UNIT_OPTIONSArray<{ label: string; value: string }>Select options derived from TIMEOUT_UNITS.
useScheduleFormMutations() => { create: MutationFunction<ApiResult<unknown>, ScheduleFormValues>; update: MutationFunction<ApiResult<unknown>, ScheduleFormValues> }Form mutations that collapse the schedule form into API params (via scheduleToParams) before submitting create/update — pluggable straight into CrudPage.formMutationFns.
useJobNames() => { options: Array<{ label: string; value: string }>; loading: boolean }The registered job names as select options (from list_jobs).
ScheduleSceneValuesCrudBasicSceneFormValues<ScheduleFormValues, ScheduleFormValues>Create and update share the schedule form shape.

Components

TriggerEditor

Props exported as TriggerEditorProps. A trigger editor: a kind switch (cron / interval / once) revealing the kind-specific fields — cron expression + timezone, interval value + unit, or a date-time picker — plus a debounced (400 ms) live preview of the next fire times via preview_fires. The preview renders inline errors for invalid expressions and an empty state when the effective window contains no fire times.

PropTypeDefaultDescription
valueTriggerFormValuesThe trigger in editor shape.
onChange(value: TriggerFormValues) => voidEmitted on every edit.
startsAtstringThe schedule's effective-window start, echoed into the fire preview.
endsAtstringThe schedule's effective-window end, echoed into the fire preview.

Trigger helpers

ExportSignatureDescription
TriggerFieldsPick<Schedule, "kind" | "expr" | "timezone" | "everyMs" | "fireAt">The subset of a schedule row that describes its trigger.
TriggerFormValues{ kind: TriggerKind; expr: string; timezone: string; intervalValue: number; intervalUnit: string; at: string }The editor's UI-facing value; the interval is a value+unit pair converted to everyMs on submit.
DEFAULT_TRIGGERconst TriggerFormValuesA fresh trigger: the cron kind with an empty expression, plus a once-a-minute interval prefilled for when the user switches kinds.
triggerToFormValues(schedule: TriggerFields) => TriggerFormValuesProjects a saved trigger into editor values.
triggerFormToParams(trigger: TriggerFormValues) => TriggerParamsConverts the editor value into wire params, keeping only the fields the chosen kind needs.
isTriggerComplete(trigger: TriggerFormValues) => booleanWhether the trigger has enough filled in to preview: a cron expression, an interval of at least the 1000 ms floor, or a chosen once time.
formatTriggerSummary(schedule: TriggerFields) => stringA one-line, humanized trigger summary for a schedule row: the cron expression (with timezone), the interval rate, or the single fire time.

Duration utilities

DurationUnit{ label: string; value: string; ms: number }, a selectable time unit paired with its size in milliseconds.

ExportSignatureDescription
INTERVAL_UNITSDurationUnit[]Units for the fixed-rate interval trigger (everyMs): 秒 / 分钟 / 小时 / 天.
TIMEOUT_UNITSDurationUnit[]Units for the per-run timeout (timeoutMs): 毫秒 / 秒 / 分钟.
combineDurationMs(value: number, unit: string, units: DurationUnit[]) => numberCombines a value expressed in unit into milliseconds. An unknown unit falls back to the first (smallest) unit; a negative value clamps to zero.
splitDurationMs(ms: number, units: DurationUnit[]) => { value: number; unit: string }Splits milliseconds into the coarsest unit that divides it evenly, so a saved everyMs/timeoutMs round-trips to the most readable value+unit. Zero maps to the smallest unit with a zero value.

Status and formatting

ExportSignatureDescription
RunStatusBadge({ status: RunStatus }) => JSX.ElementA run's lifecycle status as a colored tag.
EnabledTag({ enabled: boolean }) => JSX.Element启用 / 停用 as a success/neutral tag.
RUN_STATUS_COLORSRecord<RunStatus, string>antd Tag color tokens per run status.
RUN_STATUS_LABELS / RUN_STATUS_OPTIONSRecord<RunStatus, string> / options arrayLabels and ready-made select options.
TRIGGER_KIND_LABELS / TRIGGER_KIND_OPTIONSRecord<TriggerKind, string> / options arrayTrigger-kind labels and options.
MISFIRE_POLICY_LABELS / MISFIRE_POLICY_OPTIONSRecord<MisfirePolicy, string> / options arrayMisfire-policy labels and options.
CONCURRENCY_POLICY_LABELS / CONCURRENCY_POLICY_OPTIONSRecord<ConcurrencyPolicy, string> / options arrayConcurrency-policy labels and options.
formatTimestamp(value?: string | null) => stringFormats a naive local wall-clock timestamp (YYYY-MM-DD HH:mm:ss), or a dash when empty.
formatDuration(ms?: number | null) => stringHumanizes a run duration: sub-second stays ms, under a minute becomes s, longer becomes min; missing/zero is a dash.

RunDetailDrawer

The run detail drawer, exported standalone. It refetches the full row through find_one so the complete, untruncated error text is always available.

PropTypeDefaultDescription
runIdstring | nullThe run to show; null keeps the drawer closed.
onClose() => voidClose handler.

Types

Base and JSON

TypeShapeNotes
CreationAudited{ id: string; createdAt?: string; createdBy?: string }Mirrors orm.CreationAuditedModel.
FullAuditedCreationAudited & { updatedAt?: string; updatedBy?: string }Mirrors orm.FullAuditedModel.
JsonValuestring | number | boolean | null | JsonValue[] | { [key: string]: JsonValue }
JsonObjectRecord<string, JsonValue>The object form used for a schedule's opaque params payload — carried verbatim to the job handler on the Go side.

Enums

Each mirrors a Go enum verbatim; display labels and colors live with the presentation components.

ExportValuesNotes
TRIGGER_KINDS / TriggerKind"cron" | "interval" | "once"How a schedule computes its fire times.
MISFIRE_POLICIES / MisfirePolicy"fire_now" | "skip"What to do with occurrences missed while a node was down or the schedule was paused: fire_now runs the gap once immediately, skip drops it.
CONCURRENCY_POLICIES / ConcurrencyPolicy"forbid" | "allow"Whether a new occurrence may start while the previous run is still going: forbid skips the overlap, allow runs them in parallel.
RUN_STATUSES / RunStatus"running" | "succeeded" | "failed" | "missed" | "skipped" | "abandoned" | "canceled"The lifecycle status of one journaled run.

Schedule

Schedule — a durable schedule row from sys/cron/schedule (extends FullAudited). Timestamps are naive local wall-clock strings (YYYY-MM-DD HH:mm:ss):

FieldTypeDescription
namestringUnique addressing name.
jobNamestringThe registered job handler.
kindTriggerKindTrigger kind.
exprstringCron expression (empty for non-cron kinds).
timezonestringCron timezone (empty = server timezone).
everyMsnumberInterval rate (0 for non-interval kinds).
fireAtstring?The once fire time.
startsAt / endsAtstring?Effective window.
paramsJsonObject?Opaque handler payload.
misfirePolicyMisfirePolicyMissed-occurrence policy.
concurrencyPolicyConcurrencyPolicyOverlap policy.
recoverbooleanRe-fire after a node crash.
timeoutMsnumberPer-run timeout (0 = global default).
isEnabledbooleanPaused when false.
nextFireAtstring?The fire cursor. A paused schedule keeps it so resuming can account for the paused gap — the list therefore hides it while paused, since it will not fire at that time.
lastFireAtstring?Last fire time.
TypeFieldsNotes
TriggerParamskind: TriggerKind, expr?: string, timezone?: string, everyMs?: number, at?: stringThe trigger definition submitted with a save. Only the fields the chosen kind needs are populated: cronexpr (+ optional timezone), intervaleveryMs (fixed rate, min 1000), onceat.
ScheduleParamsname: string, newName?: string, jobName: string, trigger: TriggerParams, params?: JsonObject, startsAt?, endsAt? (string), misfirePolicy?: MisfirePolicy, concurrencyPolicy?: ConcurrencyPolicy, recover?: boolean, timeoutMs?: number, enabled?: booleanCreate/update payload. Addressing is by name; on update an optional newName renames the schedule.
ScheduleSearchname?, jobName? (string), kind?: TriggerKind, isEnabled?: stringisEnabled is a "true" / "false" toggle string — framework select values are strings — which findPage converts to the boolean the wire eq filter expects.
ScheduleNameParamsname: stringAddressing payload for the name-keyed actions (get / delete / pause / resume / trigger_now).
ScheduleDetailschedule: Schedule, nextFires: string[]The get result; nextFires is empty when the schedule is paused or spent.
PreviewFiresParamstrigger: TriggerParams, startsAt?: string, endsAt?: stringThe trigger is validated exactly like a save, so an invalid expression comes back as a business error.
PreviewFiresResultnextFires: string[]The next fire times inside the effective window.

Run

Run — one journaled run from sys/cron/run (extends CreationAudited). Read-only:

FieldTypeDescription
scheduleIdstringOwning schedule's id.
scheduleNamestringOwning schedule's name.
jobNamestringThe handler that ran.
scheduledAtstringThe occurrence's planned time.
statusRunStatusLifecycle status.
nodeIdstringThe cluster node that claimed the run.
startedAt / finishedAtstring?Actual execution bounds.
durationMsnumberExecution duration.
heartbeatAtstring?Last heartbeat while running.
errorstring?Failure text (full text via find_one).
missedCountnumber?For missed runs: how many occurrences were dropped.
TypeFieldsNotes
RunSearchscheduleName?, jobName? (string), status?: RunStatus, nodeId?: string, scheduledAtFrom?: string, scheduledAtTo?: stringThe scheduledAt* fields bound the scheduled time (gte / lte).
RunIdParamsid: stringAddressing payload for the single-run fetch (find_one).

Page prop types (CronSchedulePageProps, CronRunPageProps, RunDetailDrawerProps) are exported alongside their components — see the Overview for the page tables.