# Commands for batches, deploys and search indexes

These commands act on what a running app keeps in its database: its batch
runs, the runs a deploy would stop, and the index a search engine keeps
an entity's words in.

| Command | Does |
|---|---|
| `jadpo batches` | Lists batch runs; `show`, `cancel` |
| `jadpo runs unfinished --build <build id>` | Lists the multi-step runs a deploy would stop |
| `jadpo search reindex <Entity>` | Rebuilds an entity's index in its search engine |

| Command | What it does |
|---|---|
| [`jadpo batches`](/docs/jadpo-batches.md) | Watch and stop batch runs. |
| [`jadpo runs`](/docs/jadpo-runs.md) | Check runs before a deploy. |
| [`jadpo search`](/docs/jadpo-search.md) | Rebuild a search index. |

## `jadpo batches`

Shows the app's batch runs, its file reads and writes and its
`batches.each` runs, and stops one
([Batches](/docs/batches-work-over-many-items.md)). `batch`
is a synonym, and it takes `--json`.

- `jadpo batches`, or `list`, is a table of the runs kept, those running
  first, then those that ended, newest first, 20 to a page (`--page`).
  Each row has the run's id, the action that started it and the helper
  (`batches.each`, `csv.read`, `json_lines.write`), its state, its
  progress against its estimated total, and how many problems it has.
  `--state` lists one state's: `running`, `finished`, `failed` or
  `cancelled`. A footer and one hint follow.
- `batches show <id>` shows one run: its progress, when it started and
  last moved or ended, when it should finish at the rate it has gone so
  far, why it failed, and its problems by row, column and rule, never a
  value, 20 to a page (`--page`).
- `batches cancel <id>` stops a running run after the batch in hand, as
  `batches.cancel` does, and logs it with the operator's name and
  database role, as `jadpo deliveries` does. A run that has ended, or
  was already asked to stop, is left as it is, and the command says so.

```text
$ jadpo batches
  id        batch                        state       progress          problems
  4fa2c09e  import_prices  csv.read      ● running   412 of about 900         3
  9b1e77d2  check_stock    batches.each  ✓ finished  21 of 21                 0

● 1 running  1 finished

→ jadpo batches show 4fa2c09e  lists its problems
```

An id is the last 8 hex digits the list shows, or more. Each run's
counts and state are what `batches.status` gives the app; the command
runs none of the app's code and reads nothing a run saved. The database
is `--url`'s, with `--store` when several stores keep runs, the
connection's setting's, or a running `jadpo dev`'s. An unknown action,
state, page or id is `cli.batches_arguments`, with the nearest, and a
database it can't reach or read is `batches.unavailable`.

## `jadpo runs unfinished`

Run it against production before a deploy. It lists the unfinished
multi-step runs and batches whose recorded path the new build changes, so
an operator knows what will stop as `diverged`
([Deploys](/docs/several-changing-calls-in-one-action.md#deploys)). It takes `--json`.

`--build` takes the new build's id, `b_` and twelve hex digits, as its
stamp carries it ([The build stamp](/docs/a-native-deployable.md#the-build-stamp)) and the manifest
lists it for each deployable. It must be the id of a build the checkout
makes; `cli.runs_arguments` names the ones it does otherwise. It shows a table of each record whose build differs and
whose action's step shape the build changes, so the record stops as
diverged, or no longer keeps, so its steps are sent again. It also lists
each running batch run whose call the build changes, which fails. A footer
and one hint follow. `--url` and `--store` work as for `jadpo deliveries`
(`runs.unavailable`).

## `jadpo search reindex`

Rebuilds the index a search engine keeps an entity's words in, from the
entity's records ([An engine instead of PostgreSQL](/docs/search.md#an-engine-instead-of-postgresql)):
after the index was emptied, on a new index, or when it fell out of step.
It takes `--json`.

- It sends each record's document, a page at a time in `id` order,
  through the connection the entity's `search:` names, as the app keeps
  it after each commit: the searched fields and the tenancy reference,
  never another field. Once the engine has answered it reads the record
  again, and sends one that changed meanwhile again, or takes out one that
  went, an erasure among them. A record erased before is gone, so it is
  never sent.
- The engine's address and credential are the connection's settings, read
  as `jadpo dev` reads them, the environment over `.env.local`; the
  database is `--url`'s, the store's connection's setting's, or a running
  `jadpo dev`'s.
- It never empties the index first: the `search` capability has no
  operation to list or clear one, and the document of a record deleted
  was taken out by the delivery its deletion made. To start from nothing,
  empty or make the index with the engine's own tools first.

```text
$ jadpo search reindex Product
✓ Rebuilt the index of `Product`  1,204 records sent to `products_index`
```

A record that went while its document was out, or before it was sent,
is counted after the records sent, as gone since and taken out. An entity the project doesn't declare,
or doesn't search in an engine, is `cli.search_arguments`, with the
nearest. A setting the connection reads that nothing gives, a database
it can't reach or read, and an engine that refuses or can't be reached
are `search.reindex_failed`: it stops at the first refusal, saying how
many records were sent, and since sending a record again changes nothing,
it can be run again from the start.
