# Cron Schedule

> Initiates workflow execution on a precise schedule using CRON syntax.

Source: https://docs.sommatic.ai/en/nodes/cron.trigger/

- Slug: `cron.trigger`
- Family: Triggers
- Version: 1.0.0
- Status: Partial. The scheduler only estimates an interval from the minute and hour fields: exact times, weekdays and the timezone are not honoured. `jitter_ms` is not applied.
- Execution: async

Initiates workflow execution on a precise schedule using CRON syntax.

This trigger is the entry point for time-based automation. It supports standard CRON expressions for defining recurring intervals (e.g., "Every Friday at 5 PM").

**Features:**
- **Standard Cron:** Full support for "* * * * *" syntax.
- **Timezones:** Schedule respects localized time zones.
- **Jitter:** Optional random delay to prevent "thundering herd" issues.

**Use Cases:**
- Generating daily reports.
- Running nightly cleanup jobs.
- Polling an API every 15 minutes.

## Configuration

- `cron_expr` (string, required): Standard cron (min hour day month day-of-week). Default: `0 0 * * *`.
- `timezone` (string, optional): Default: `UTC`.
- `payload_template` (object, optional): Optional JSON to inject into the workflow start context.

## Output ports

- `out` (default): Workflow Started.
- `error`: Error

## Output contract

- `timestamp` (string, optional)
- `schedule_time` (string, optional)

## In expressions

What a later node can read from this node's output with `$("Cron Schedule").item.json.<path>` (write your node's label instead of `Cron Schedule`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Cron Schedule").item.json.timestamp` (string) = `"2026-11-26T00:00:03.120-05:00"`
- `$("Cron Schedule").item.json.schedule_time` (string) **The worker does not return it: reads as undefined.**
- `$("Cron Schedule").item.json.$scheduled` (boolean) = `true` (Not suggested by the editor)
- `$("Cron Schedule").item.json.$trigger_state` (object) = `{…}` (Not suggested by the editor)
- `$("Cron Schedule").item.json.$trigger_state.lastExecutedAt` (string) = `"2026-11-25T05:00:02.311Z"` (Not suggested by the editor)
- `$("Cron Schedule").item.json.report` (string) = `"daily-sales"` (Not suggested by the editor)
- `$("Cron Schedule").item.json.schedule` (string) = `"0 0 * * *"` (Not suggested by the editor)
- `$("Cron Schedule").item.json.timezone` (string) = `"America/New_York"` (Not suggested by the editor)


## How it works

Entry node of scheduled workflows. When the backend scheduler starts the run, the node outputs the incoming input merged with `payload_template`, plus `timestamp`, `schedule` and `timezone`.

1. What starts it: the backend scheduler checks every 10 seconds the active workflows that have a published version and contain this node, and starts the published version when the estimated interval of `cron_expr` has passed since its last start (when no previous start is recorded, it starts at once). The run receives `{ $scheduled: true }` plus the stored `$trigger_state`.
2. The interval is estimated from the minute and hour fields: `*` → every minute, `*/N` → every N minutes, a fixed minute with `*` hour → every hour, anything else → every day. Exact times, day-of-week and day-of-month fields are not matched.
3. When the node runs, it resolves its config (`cron_expr` default `0 0 * * *`, `timezone` default `UTC`, `payload_template` default `{}`) and takes the current time in `timezone`.
4. Outputs `{ ...input, ...payload_template, timestamp, schedule, timezone }` on `out`, with `meta: { triggered_at, jitter_applied }`.

## In a workflow

### Node

```json
{
  "node_id": "node-nightly",
  "label": "Every night",
  "operator_slug": "cron.trigger",
  "operator_version": "1.0.0",
  "config": {
    "cron_expr": "0 0 * * *",
    "timezone": "America/New_York",
    "payload_template": {
      "report": "daily-sales"
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "$scheduled": true,
    "$trigger_state": {
      "lastExecutedAt": "2026-11-25T05:00:02.311Z"
    },
    "report": "daily-sales",
    "timestamp": "2026-11-26T00:00:03.120-05:00",
    "schedule": "0 0 * * *",
    "timezone": "America/New_York"
  },
  "port": "out",
  "meta": {
    "triggered_at": "2026-11-26T00:00:03.120-05:00",
    "jitter_applied": 0
  }
}
```

## Output ports (behaviour in the code)

### `out`

Always. `$scheduled` and `$trigger_state` come from the scheduler's input; a manual run has only the input you provide.

```json
{
  "$scheduled": true,
  "$trigger_state": {
    "lastExecutedAt": "2026-11-25T05:00:02.311Z"
  },
  "report": "daily-sales",
  "timestamp": "2026-11-26T00:00:03.120-05:00",
  "schedule": "0 0 * * *",
  "timezone": "America/New_York"
}
```

### `error`

Declared but never emitted by the code.

## Behaviour in the code

- `cron_expr`: Not validated by the node. The scheduler only derives an interval from it (see operation), so `0 9 * * 1-5` runs once a day, measured from the last start, not at 09:00 on weekdays.
- `timezone`: Only formats `timestamp` and `meta.triggered_at`; it does not affect when the scheduler starts the run. An invalid zone name produces `timestamp: null`.
- `payload_template`: Its keys override keys of the incoming input with the same name; `timestamp`, `schedule` and `timezone` always override the template.
- `jitter_ms`: Read but not declared, and not applied: no delay is added. Its value is only echoed in `meta.jitter_applied`.

## Notes and limits

- Test vs production: only the published version is started by the scheduler; a draft never runs on its own. A manual run executes the node immediately, without `$scheduled`. With sample data the engine skips the node and passes the sample input on `out`.
- The scheduler reads the trigger config from the workflow draft but runs the published version.
- `schedule_time`, listed in the output contract, is never produced.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "cron.trigger",
  "name": "Cron Schedule",
  "category": "triggers",
  "version": "1.0.0",
  "description": "Initiates workflow execution on a precise schedule using CRON syntax.\n\n  This trigger is the entry point for time-based automation. It supports standard CRON expressions for defining recurring intervals (e.g., \"Every Friday at 5 PM\").\n\n  **Features:**\n  - **Standard Cron:** Full support for \"* * * * *\" syntax.\n  - **Timezones:** Schedule respects localized time zones.\n  - **Jitter:** Optional random delay to prevent \"thundering herd\" issues.\n\n  **Use Cases:**\n  - Generating daily reports.\n  - Running nightly cleanup jobs.\n  - Polling an API every 15 minutes.",
  "capabilities": [
    "scheduling",
    "time-based",
    "cron"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "cron_expr"
    ],
    "properties": {
      "cron_expr": {
        "type": "string",
        "title": "CRON Expression",
        "default": "0 0 * * *",
        "description": "Standard cron (min hour day month day-of-week)."
      },
      "timezone": {
        "type": "string",
        "default": "UTC",
        "title": "Timezone",
        "ui_widget": "timezone_picker"
      },
      "payload_template": {
        "type": "object",
        "title": "Static Payload",
        "description": "Optional JSON to inject into the workflow start context."
      }
    }
  },
  "input_contract_schema": null,
  "output_contract_schema": {
    "type": "object",
    "description": "Schedule metadata.",
    "properties": {
      "timestamp": {
        "type": "string",
        "format": "date-time"
      },
      "schedule_time": {
        "type": "string",
        "format": "date-time"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Start",
      "is_default": true,
      "description": "Workflow Started."
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "schedule",
    "time",
    "start",
    "trigger"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "required": [
    "cron_expr"
  ],
  "properties": {
    "cron_expr": {
      "type": "string",
      "title": "CRON Expression",
      "default": "0 0 * * *",
      "description": "Standard cron (min hour day month day-of-week)."
    },
    "timezone": {
      "type": "string",
      "default": "UTC",
      "title": "Timezone",
      "ui_widget": "timezone_picker"
    },
    "payload_template": {
      "type": "object",
      "title": "Static Payload",
      "description": "Optional JSON to inject into the workflow start context."
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "Schedule metadata.",
  "properties": {
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "schedule_time": {
      "type": "string",
      "format": "date-time"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Start",
    "is_default": true,
    "description": "Workflow Started."
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
