# Job lifecycle

> Job states and the calls that move them.

## Job states

```steps
pending: Ready for a bot
in_progress: A bot works on it
completed: Done
```

| State | Meaning |
| --- | --- |
| `draft` | Being prepared. Never assigned or started. |
| `scheduled` | Waits for its time. |
| `pending` | Ready to be assigned and started. |
| `in_progress` | A bot is working on it. |
| `paused` | On hold. |
| `completed`, `failed`, `canceled` | Final. |

## The calls that move it

| Call | From | To |
| --- | --- | --- |
| [`activate`](https://docs.remi.robot.com/engine/reference#activateJob) | `draft` | `pending` |
| [`schedule`](https://docs.remi.robot.com/engine/reference#scheduleJob) | `draft` | `scheduled` |
| [`start`](https://docs.remi.robot.com/engine/reference#startJob) | `pending`, `scheduled` | `in_progress` |
| [`pause`](https://docs.remi.robot.com/engine/reference#pauseJob) | `in_progress` | `paused` |
| [`resume`](https://docs.remi.robot.com/engine/reference#resumeJob) | `paused` | `in_progress` |
| [`complete`](https://docs.remi.robot.com/engine/reference#completeJob) | `in_progress` (expendable) | `completed` |
| [`fail`](https://docs.remi.robot.com/engine/reference#failJob) | active | `failed` |
| [`cancel`](https://docs.remi.robot.com/engine/reference#cancelJob) | active | `canceled` |

All are `POST /engine/jobs/{id}/<call>`. A job also completes on its own when its last node finishes.

## Bots

- With `assignation: auto`, REMI assigns a bot. With `manual`, use [`assign-bot`](https://docs.remi.robot.com/engine/reference#assignBot).
- With `start: auto`, the job starts once its bot is free. With `manual`, call `start`.
- [`swap-bots`](https://docs.remi.robot.com/engine/reference#swapJobBots) and [`transfer-bot`](https://docs.remi.robot.com/engine/reference#transferJobBot) move bots between two jobs at the same location.
- A job with `requiresBot: false` runs with no bot at all.

## Nodes and actions

Node states: `pending`, `in_progress`, `completed`, `failed`. Action states add `paused`, `skipped` and `canceled`.

- Your own action types stay `in_progress` until you [complete](https://docs.remi.robot.com/engine/reference#completeAction), [fail](https://docs.remi.robot.com/engine/reference#failAction) or [skip](https://docs.remi.robot.com/engine/reference#skipAction) them.
- `load` and `unload` finish with [load](https://docs.remi.robot.com/engine/reference#loadPackage) and [unload](https://docs.remi.robot.com/engine/reference#unloadPackage): the bot closes its door and the action completes.
- A node created with `released: false` waits for [release](https://docs.remi.robot.com/engine/reference#releaseNode) before the job moves on.
- [`jump-to`](https://docs.remi.robot.com/engine/reference#jumpToNode) sends a running job straight to a later node.

## Concurrent edits

Each job has a `version` that goes up by one on every change. To reject a change made on top of someone else's, send the current `version` plus one: `nextVersion` on the lifecycle calls, `version` on `PATCH`. A mismatch answers `JOB_VERSION_MISMATCH`.
