# Job

A job and where it is.

## Fields

- `created_at` (string, RFC 3339, required)
- `id` ([JobId](/docs/types/job-id.md) (string, pattern), required): A job's ID: `job_` and then the job's UUID in 26 characters of base32, as a TypeID (github.com/jetify-com/typeid).
- `request` ([JobRequest](/docs/types/job-request.md), required): The request as the API accepted it.
  - `exclusive` (boolean, required): Whether only this customer may ever see the job's results. It cannot change later.
  - `reuse` (boolean, required): Whether the lab may hand back results it already measured for the same reaction, at the reuse rate, instead of running it again. The match is exact: every field the two reactions state must agree, and an earlier synthesis must have been for at least the amount, with a measured purity of at least the purity asked for.
  - `work` ([Work](/docs/types/work.md) (one of 4 kinds, by kind), required): Which of the four jobs this is, and what it needs. `kind` says which.
    - Variant `kind = "route_review"`: Chemists review a route to a target and say what they would change. It hands back their review and no rewards.
      - `kind` ("route_review", required)
      - `route` (array of [Reaction](/docs/types/reaction.md), at least 1, required): The route's reactions, in order.
      - `target_smiles` ([Smiles](/docs/types/smiles.md) (string, pattern `^[!-~]+$`), required): A molecule as SMILES. The lab checks the chemistry; the API checks only that it is printable ASCII without spaces.
    - Variant `kind = "reaction_batch"`: The lab runs each reaction. Each hands back its yield.
      - `kind` ("reaction_batch", required)
      - `reactions` (array of [Reaction](/docs/types/reaction.md), at least 1, required): At least one reaction, with unique IDs, so that a reward can name one.
    - Variant `kind = "reaction_screen"`: The lab runs each reaction as one well of a plate. Each hands back its conversion or yield.
      - `kind` ("reaction_screen", required)
      - `reactions` (array of [Reaction](/docs/types/reaction.md), at least 1, required): At least one reaction, with unique IDs, so that a reward can name one.
    - Variant `kind = "synthesis"`: The lab makes an amount of a target at a purity. It hands back the final yield and purity.
      - `kind` ("synthesis", required)
      - `amount_mg` ([Positive](/docs/types/positive.md) (number, above 0, at most 10¹²), required): An amount greater than zero, up to 10¹².
      - `max_credits` ([Positive](/docs/types/positive.md) (number, above 0, at most 10¹²), required): The most credits the job may cost. The job holds them until it completes.
      - `purity_pct` ([Percent](/docs/types/percent.md) (number, 0 to 100), required): A percentage, from 0 to 100.
      - `target_smiles` ([Smiles](/docs/types/smiles.md) (string, pattern `^[!-~]+$`), required): A molecule as SMILES. The lab checks the chemistry; the API checks only that it is printable ASCII without spaces.
      - `route` (array of [Reaction](/docs/types/reaction.md), at least 1 or null): The route to follow, in order. Leave it out for the lab to choose one.
- `reused` (array of [Name](/docs/types/name.md) (string, at most 200 chars, pattern), required): The IDs of the request's reactions answered by results measured for an earlier job, which the lab does not run and which cost the reuse rate. A synthesis is served whole or not at all, and lists `target` when it is. It is empty when the job reuses nothing, and until the lab may see the job, seconds after it is made.
- `status` ([JobStatus](/docs/types/job-status.md) (one of "queued", "running", "completed", "canceled"), required): Where a job is. The database works it out; a job starts when the lab sends its first record for it. A job the lab reopens to correct or add to its data is `running` again until its next package is ready.
- `canceled_at` (string, RFC 3339 or null)
- `completed_at` (string, RFC 3339 or null): When the job's newest package was written. It is null while the job is not `completed`.
- `credits` ([NonNegative](/docs/types/non-negative.md) (number, 0 to 10¹²) or null): What the job holds until it completes, then what it cost, in credits. It is null for a lab system's key.
- `package_version` (integer, at least 0 or null): The number of the job's newest package: 1 for its first, and one more each time the lab reopens the job and finishes it again. Compare it with the version you hold to see a new package. It is null until the first.
- `started_at` (string, RFC 3339 or null)

## Used by

- [POST /v1/jobs](/docs/jobs/create-job.md)
- [GET /v1/jobs/{id}](/docs/jobs/get-job.md)
- [POST /v1/jobs/{id}/cancel](/docs/jobs/cancel-job.md)
- [JobList](/docs/types/job-list.md)
