ObjectStackObjectStack

Job

Job protocol schemas

Cron Schedule Schema Schedule jobs using cron expressions

Source: packages/spec/src/system/job.zod.ts

TypeScript Usage

import { CronScheduleSchema, IntervalScheduleSchema, JobSchema, JobExecutionSchema, JobExecutionStatus, OnceScheduleSchema, RetryPolicySchema, ScheduleSchema } from '@objectstack/spec/system';
import type { CronSchedule, IntervalSchedule, Job, JobExecution, JobExecutionStatus, OnceSchedule, RetryPolicy, Schedule } from '@objectstack/spec/system';

// Validate data
const result = CronScheduleSchema.parse(data);

CronSchedule

Properties

PropertyTypeRequiredDescription
type'cron'
expressionstring | { dialect: Enum<'cel' | 'cron' | 'template'>; source?: string; ast?: any; meta?: object }Cron expression — cron0 0 * * * for daily at midnight. Build emits {dialect:"cron",source} envelope.
timezonestringoptionalTimezone for cron execution (e.g., "America/New_York")

IntervalSchedule

Properties

PropertyTypeRequiredDescription
type'interval'
intervalMsintegerInterval in milliseconds

Job

Properties

PropertyTypeRequiredDescription
namestringJob name (snake_case)
labelstringoptionalHuman-readable label
descriptionstringoptionalJob description / purpose
schedule{ type: 'cron'; expression: string | object; timezone?: string } | { type: 'interval'; intervalMs: integer } | { type: 'once'; at: string }Job schedule configuration
handlerstringHandler function name (must match a key in defineStack({ functions }))
retryPolicy{ maxRetries?: integer; backoffMs?: integer; backoffMultiplier?: number; maxRetryDelayMs?: integer; … }optionalRetry policy: failed runs (including timeouts) are retried with exponential backoff (delay = min(backoffMs * backoffMultiplier^(retry-1), maxRetryDelayMs), optionally jittered) up to maxRetries retries after the initial attempt (#3494). Omit the block for a single attempt; declaring it without maxRetries also means no retry since 17.0.0 (#4661) — state a count to opt in.
timeoutintegeroptionalPer-attempt time limit in milliseconds; an over-limit run is recorded with execution status "timeout" (#3494). The in-flight handler is abandoned, not forcibly cancelled. Omit for no time limit.
enabledbooleanoptionalWhether the job is enabled
_lockEnum<'none' | 'no-overlay' | 'no-delete' | 'full'>optionalItem-level lock — controls overlay & delete (ADR-0010).
_lockReasonstringoptionalHuman-readable reason shown when a write is refused by _lock.
_lockSourceEnum<'artifact' | 'package' | 'env-forced'>optionalLayer that set _lock (artifact | package | env-forced).
_provenanceEnum<'package' | 'org' | 'env-forced'>optionalOrigin of the item (package | org | env-forced).
_packageIdstringoptionalOwning package machine id.
_packageVersionstringoptionalOwning package version.
_lockDocsUrlstringoptionalOptional documentation link surfaced next to _lockReason.

JobExecution

Properties

PropertyTypeRequiredDescription
jobIdstringJob identifier
startedAtstringISO 8601 datetime when execution started
completedAtstringoptionalISO 8601 datetime when execution completed
statusEnum<'running' | 'success' | 'failed' | 'timeout' | 'degraded'>Execution status
errorstringoptionalError message if failed
durationMsintegeroptionalExecution duration in milliseconds

JobExecutionStatus

Allowed Values

  • running
  • success
  • failed
  • timeout
  • degraded

OnceSchedule

Properties

PropertyTypeRequiredDescription
type'once'
atstringISO 8601 datetime when to execute

RetryPolicy

Properties

PropertyTypeRequiredDescription
maxRetriesintegerRetry attempts after the initial one. 0 (the default) means no retry — state a count to opt in.
backoffMsintegerBase delay before the first retry (ms); subsequent delays multiply by backoffMultiplier
backoffMultipliernumberExponential backoff multiplier; 1 (the default) keeps the delay flat
maxRetryDelayMsintegerCeiling for a single backoff delay (ms)
jitterbooleanRandomize each delay within [50%, 100%] of its computed value — spreads a thundering herd of simultaneous retries
retryDelayMsneveroptional[REMOVED] retryDelayMs was removed in @objectstack/spec 17.0.0 (#4661, #4964) — the retry policy now has ONE spelling for its base delay across every surface that carries it: job.retryPolicy, a try_catch node's retry and flow.errorHandling. Rename the key to backoffMs; the value (milliseconds before the first retry) is unchanged. Run os migrate meta --from 16 to rewrite existing sources automatically.

Schedule

Union Options

This schema accepts one of the following structures:

Option 1

Type: cron

Properties

PropertyTypeRequiredDescription
type'cron'
expressionstring | { dialect: Enum<'cel' | 'cron' | 'template'>; source?: string; ast?: any; meta?: object }Cron expression — cron0 0 * * * for daily at midnight. Build emits {dialect:"cron",source} envelope.
timezonestringoptionalTimezone for cron execution (e.g., "America/New_York")

Option 2

Type: interval

Properties

PropertyTypeRequiredDescription
type'interval'
intervalMsintegerInterval in milliseconds

Option 3

Type: once

Properties

PropertyTypeRequiredDescription
type'once'
atstringISO 8601 datetime when to execute


On this page