# Cron

> Fire a trigger on an interval, a cron expression or musical beats, with the time as JSON.

Source: https://docs.tune.toys/nodes/time.cron/

Cron is the data domain's clock. It sends a trigger every few seconds, at the times a cron expression names, or on musical beats, and it sends the time with each tick as JSON.

## What it does

Each tick sends `true` on `tick` and an object on `time`: `{ iso, epochMs, beat, bar, count }`, where `count` starts at 1. Ticks are stamped with the audio block they belong to, so they line up with the sound rather than with a UI timer.

Cron only ticks while the transport rolls. Pressing Play starts it; stopping, seeking or changing tempo re-arms it. A cabled `enable` input pauses it while `false`.

Cron runs in the browser's data runtime. The Player and exports report the data domain unavailable at load, so it does not tick there.

## When to use it

Use it to drive anything that should happen again and again: pick a new [Random](https://docs.tune.toys/nodes/data.random/) value, refresh a [Web request](https://docs.tune.toys/nodes/web.request/), play a [JSON melody](https://docs.tune.toys/nodes/midi.from-data/) every bar, or log the time to the [Console](https://docs.tune.toys/nodes/log.console/).

## Ports

<!-- ports:start -->

| Port     | Direction | Signal         | Lanes |
| -------- | --------- | -------------- | ----- |
| `enable` | Input     | Data (boolean) | 1     |
| `tick`   | Output    | Data (trigger) | 1     |
| `time`   | Output    | Data (json)    | 1     |

<!-- ports:end -->

## Parameters

<!-- parameters:start -->

| Parameter  | Label    | Range        | Default | Unit | Scale  | Notes                                                                                                                                                 |
| ---------- | -------- | ------------ | ------- | ---- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mode`     | Mode     | 0 to 2       | 0       |      | linear | Interval fires every few seconds, Cron follows the expression in the host time zone, Beat follows the transport. Choices: 0 Interval, 1 Cron, 2 Beat. |
| `interval` | Interval | 0.05 to 3600 | 1       | s    | log    | Seconds between ticks in Interval mode.                                                                                                               |
| `division` | Division | 0 to 5       | 2       |      | linear | Note value between ticks in Beat mode. Choices: 0 Whole, 1 Half, 2 Quarter, 3 Eighth, 4 Sixteenth, 5 Bar.                                             |
| `limit`    | Limit    | 0 to 100000  | 0       |      | linear | Stop after this many ticks; 0 runs until stopped.                                                                                                     |

<!-- parameters:end -->

<!-- data:start -->

- `expression`: cron.

<!-- data:end -->

### Mode (`mode`)

Interval ticks every Interval seconds, counted from when the transport starts; ticks are targeted at exact frames, so they never drift. Cron follows the node's cron expression in the host's time zone. Beat ticks on the transport's beats at the chosen Division.

### Interval (`interval`)

Seconds between ticks in Interval mode, from 0.05 to 3600. The first tick arrives one interval after Play.

### Division (`division`)

The note value between ticks in Beat mode: whole, half, quarter, eighth or sixteenth notes, or one bar of the current time signature.

### Limit (`limit`)

Stop after this many ticks. 0 runs until the transport stops.

### Cron expression

The node's `expression` field takes five fields (`minute hour day month weekday`) or six with seconds first, such as `*/5 * * * * *` for every five seconds. The inspector previews the next five runs. It is used only in Cron mode.

## Tips

- Nothing happens until you press Play: Cron follows the transport.
- Use Beat mode for anything musical. It follows tempo changes, while Interval keeps clock time.
- Wire `tick` to triggers and `time` to [Console log](https://docs.tune.toys/nodes/log.console/) to see when each tick happened.

## See also

[Random](https://docs.tune.toys/nodes/data.random/), [Console log](https://docs.tune.toys/nodes/log.console/), [Data to MIDI](https://docs.tune.toys/nodes/midi.from-data/), [Data cables](https://docs.tune.toys/concepts/data-cables/), [Takes](https://docs.tune.toys/concepts/takes/).
