# Start stations

Four things can start a station run. Each one creates a `pending` work record, which a factory session then picks up. The trigger decides only *when* a run starts, not what it does.

| Trigger | Set in the station file | Decided by | Starts a run when |
|---|---|---|---|
| By hand | — | you | you run `al-orc stations run IN1`, or press Run in the Orchestrator |
| Schedule | `schedule_enabled`, `schedule_cron` | the Orchestrator | the cron expression is due |
| Bin-watch | `watch_enabled` (station has a `conveyor`) | your factory session | a workpiece waits in the station's own `input` |
| Intake watch | `watch_enabled`, plus `watch_path` in its `config` (line head) | your factory session | the line head's inbox folder or file has something in it |

`schedule_enabled` and `watch_enabled` are independent. A station can have both: the watch for speed, and a slow cron as a safety net. With neither, only a person starts it.

## Schedule

The Orchestrator checks every minute. A station is due when its `schedule_cron` has come round since its last run, in `schedule_timezone` (UTC if unset).

```json
{ "schedule_enabled": true, "schedule_cron": "*/5 * * * *", "schedule_timezone": "UTC" }
```

`schedule_cron` is a standard five-field cron expression (minute, hour, day of month, month, day of week), read in `schedule_timezone`, an IANA name such as `UTC` or `Asia/Kolkata`. `"0 8 * * *"` in `Asia/Kolkata` runs at 8:00 in India, 2:30 UTC.

| `schedule_cron` | Runs |
|---|---|
| `*/15 * * * *` | Every 15 minutes |
| `0 8 * * *` | Every day at 8:00 |
| `0 9 * * 1` | Every Monday at 9:00 |
| `0 0 1 * *` | At midnight on the first of each month |

To turn a schedule on or off, set `schedule_enabled` in the station file and push it (`al-orc stations push --all`). A station also needs `is_enabled: true`, the default, for its schedule to fire. With the schedule off, you can still run the station by hand.

- **One run at a time.** If the station already has a `pending` or `running` run, the Orchestrator skips it.
- **Work moves at the speed of the cron.** A station on `*/5` picks up new work up to five minutes late.
- **It runs even when there is nothing to do,** and each run creates a work record. Every minute is the fastest schedule; for anything quicker, use a watch.

## Bin-watch

Bin-watch runs in your factory session, not in the Orchestrator. Start it next to the session in `src/index.js`, as the factory template does:

```js
const stations = await discoverStations(new URL('./stations', import.meta.url));
startFactory({ stations, callerUrl: import.meta.url });
startBinWatcher();
```

`startBinWatcher()` also runs the [conveyor](/docs/guides/connect-stations), which fills each station's `input` from the bins its `conveyor.from` names, every 2 seconds.

Then set `"watch_enabled": true` on each station it should start. One rule: every 10 seconds it checks each watched station's own `input`, and if a workpiece is there and no run is in flight, it starts one. It counts only workpieces, meaning folders with a `pointer.json`. A run takes at most its batch, so work left over starts the next run once this one ends.

A watched station must:

- belong to a line whose `location` matches this session's `FACTORY_LOCATION`;
- have been pushed (`al-orc stations push --all`), so it has an `id`;
- have a `conveyor`, or be a line head with a `watch_path` (see Intake watch below).

A waiting station always holds work in its `input/`, so run it on a schedule, not a watch: see [Hold a workpiece](/docs/guides/hold-work).

If any of these is missing, the factory session refuses to start, so a broken watch can't fail without anyone noticing. A missing `.orchestrator/lines/` folder stops it too, and so does a station file that still has `steps`, the format before lib-factory 0.41: see [Station files](/docs/guides/factory-repo#station-files).

## Intake watch

A line head has no upstream bin, so the bin-watcher starts it from its inbox instead. Add `watch_path` to its `config`, next to the station's own settings, and set `"watch_enabled": true`:

```json
{ "short_code": "IN0", "config": { "inbox_dir": "temp/inbox", "watch_path": "temp/inbox" }, "watch_enabled": true }
```

`watch_path` is a key of its own even when it repeats one the station reads, so the watcher doesn't depend on how your station names its settings. A relative path is resolved from the factory root.

- **A folder has work** when it holds anything not starting with `.`. **A file has work** when it isn't empty.
- **A missing path** prints a warning when the session starts and counts as empty until it appears.
- **The line head must empty its inbox.** Anything it leaves behind, such as a file it can't read, starts a run every 10 seconds. Move such files somewhere outside the watched path.

A line head with nothing to watch, such as one that checks a mailbox, stays on a schedule.

## Behaviours to know

- **Restart after changing `watch_enabled` or `conveyor`.** The session reads which stations to watch and convey for from your local files when it starts. Push the change as well, so the Orchestrator's copy matches.
- **A warning lists stations nothing starts.** When the session starts, it names every station with a conveyor (and every line head that feeds one) with neither a schedule nor a watch. The conveyor still fills such a station's `input`; nothing runs it.
- **Two runs can still start together.** The scheduler and the watcher each check for a run in flight and then start one, so with both on, two runs can begin in the same moment.
- **Each run records who started it.** A scheduled run has no `performed_by`; a run started through the API, including every watcher run, has `performed_by: "api"`. List a station's runs with `al-orc work-records list --station IN1`.
- **A disabled or archived station with `watch_enabled` keeps being tried.** The Orchestrator refuses each run and the watcher logs the error every 10 seconds. Turn the watch off when you disable a station.

The station fields are in the [station object reference](https://orchestrator.assemblyline.sh/docs/objects/station).
