# Statuses

> List running work and cancel it

`client.statuses` reads what the dashboard's Running page shows: ingests,
check runs, training jobs and pipeline runs that are queued or running, and
work that ended recently. Each item is a `qualia.v1.Status`, one operation
rebuilt from its latest state change. Work is named under its workspace,
`accounts/{a}/workspaces/{w}/statuses/{operation}`, or under the organization
for the organization's own work. `accounts/{a}/statuses/{operation}` reads any
of them.

## List running work

```python
from datetime import timedelta

from qualia import Qualia

client = Qualia()

page = client.statuses.list(filter="state = QUEUED OR state = RUNNING")
for status in page.items:
    progress = status.progress
    print(status.operation, status.kind, status.state,
          progress and f"{progress.phase} {progress.done}/{progress.total}")

whole_org = client.statuses.list(organization=True, recent=timedelta(days=7))
```

| Argument       | Description                                                                                                               |
| -------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `parent`       | A workspace ID or `accounts/{a}/workspaces/{w}`. Defaults to the workspace the client acts in.                            |
| `organization` | `True` lists the whole organization: every workspace's work and the organization's own.                                   |
| `recent`       | How far back ended work goes, as a `timedelta` or seconds. Default 24 hours, at most 90 days.                             |
| `filter`       | AIP-160 on `state`, `kind` and `service`, e.g. `service = "pipeline" AND state != FAILED`. `OR` binds tighter than `AND`. |
| `limit`        | Page size; the server's default is 100, its maximum 500.                                                                  |
| `cursor`       | `page.page_info.end_cursor` of the previous page.                                                                         |

The list is a `PaginatedPage`; follow `page.page_info.end_cursor` while
`page.page_info.has_next`. Pages follow the order at each read, so work that
changes between reads may show on two pages or on neither.

A key restricted to workspaces can neither list nor cancel work.

## Cancel work

```python
status = client.statuses.cancel(status.name)
# or by operation ID, read through the organization
status = client.statuses.cancel("3f2b8c1e-7d4a-4e9b-9c2f-0a6e5d1b8f47")
```

`cancel` asks the service that runs the work to stop it and returns once the
service accepted. The status still reads as before; it turns `CANCELLED` a
moment later. It needs `jobs:write` and a contributor role on the work's
workspace, whichever name you pass. Work that has ended, or whose kind cannot
be cancelled (`status.cancellable` is false), is refused. A check run's status
is cancellable: a running VLM or heuristic run stops with its pipeline run and
reads failed, "cancelled by" you; another check's run is refused with a reason.

The CLI has the same: `qualia status list` and `qualia status cancel`.
