clabe.hub ¶
The clabe hub: an optional service (e.g. in Docker) that follows a fleet of rigs through their daemons, shows
which ones wait for an answer, and re-exposes each rig under /rigs/<id>/ so the web UI works fleet-wide.
Rigs never depend on it: the hub dials in as an ordinary client of their daemons.
Fleet ¶
Fleet(
settings: HubSettings,
client: AsyncClient | None = None,
reports: ReportStore | None = None,
)
Polls every rig's daemon (and, when it runs an experiment, the run) and keeps what it saw.
With a report store, it also collects each rig's issue reports (every report_interval seconds, when the rig
has some): downloads each, stores it, and only then deletes it on the rig.
Source code in src/clabe/hub/_fleet.py
rig ¶
statuses ¶
Every rig as last polled (or those given), with how many of its reports the hub stores.
Source code in src/clabe/hub/_fleet.py
inbox ¶
The rigs waiting for an answer, longest-waiting first.
Source code in src/clabe/hub/_fleet.py
poll_once
async
¶
poll_once(*, collect: bool = False) -> None
Refreshes every rig's status, and collects reports where due (or everywhere, with collect).
Source code in src/clabe/hub/_fleet.py
run
async
¶
start ¶
stop
async
¶
collect
async
¶
Collects a rig's issue reports: downloads each one not stored yet, stores it, then deletes it on the rig (one already stored is just deleted there). Failures are logged and retried next time.
Returns:
| Type | Description |
|---|---|
int
|
How many reports were stored. |
Source code in src/clabe/hub/_fleet.py
HubSettings ¶
Bases: EnvSettings
Settings of clabe hub run, from environment variables without a prefix (the hub runs in its own container)
or a .env file in the working directory (see docker/hub/.env.example). Rigs are id=url items separated
by ; (or a JSON list, for per-rig tokens):
TOKEN=... # the hub's own
RIG_TOKEN=... # the rigs' daemon token (their DAEMON_CLABE_TOKEN)
RIGS=rig-3=http://rig-3:24070;rig-4=http://rig-4:24070
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]
Keyword arguments, then the environment, then a .env file when the class names one.
Source code in src/clabe/settings.py
RigConfig ¶
Bases: BaseModel
A rig the hub follows.
RigStatus ¶
Bases: BaseModel
What the hub last saw of a rig.
Waiting ¶
Bases: BaseModel
A prompt a rig's run is waiting on.
InspectCache ¶
Exports opened for a look, kept in a temporary folder for INSPECT_TTL seconds after their last use.
Source code in src/clabe/hub/_reports.py
directory
property
¶
directory: Path
Where the exports are kept (a temporary folder, made at first use, unless one was given).
add ¶
add(data: bytes) -> InspectResult
Keeps an export for a look.
Raises:
| Type | Description |
|---|---|
ValueError
|
Not a zip. |
Source code in src/clabe/hub/_reports.py
path ¶
The zip of an opened export, if still kept (its use keeps it longer).
Source code in src/clabe/hub/_reports.py
expire ¶
Forgets the exports unused for longer than the time they are kept.
Source code in src/clabe/hub/_reports.py
ReportPage ¶
Bases: BaseModel
A page of reports, and how many match in all.
ReportStore ¶
ReportStore(data_dir: Path)
The hub's collected reports: rows in SQLite, zips on disk. Safe to use from several threads.
Source code in src/clabe/hub/_reports.py
close ¶
has ¶
add ¶
add(rig_id: str, data: bytes) -> StoredReport | None
Stores a report's zip (its id is that of its report.json); None if it was stored already.
Raises:
| Type | Description |
|---|---|
ValueError
|
Not a report's zip. |
Source code in src/clabe/hub/_reports.py
get ¶
get(report_id: str) -> StoredReport | None
Report report_id, if stored.
Source code in src/clabe/hub/_reports.py
zip_path ¶
Where report report_id's zip is, if stored.
Source code in src/clabe/hub/_reports.py
query ¶
query(
*,
rig: str | None = None,
experiment: str | None = None,
status: ReportStatus | None = None,
q: str | None = None,
sort: ReportSort = "created_at",
order: Literal["asc", "desc"] = "desc",
limit: int = 100,
offset: int = 0,
) -> ReportPage
The reports matching every filter given, sorted, a page at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rig
|
str | None
|
Only from this rig. |
None
|
experiment
|
str | None
|
Only of this experiment. |
None
|
status
|
ReportStatus | None
|
Only in this status. |
None
|
q
|
str | None
|
Only those with this text (any case) in any text column. |
None
|
sort
|
ReportSort
|
The column to sort by. |
'created_at'
|
order
|
Literal['asc', 'desc']
|
|
'desc'
|
limit
|
int
|
At most this many. |
100
|
offset
|
int
|
Skipping this many first. |
0
|
Source code in src/clabe/hub/_reports.py
set_status ¶
set_status(
report_id: str, status: ReportStatus
) -> StoredReport | None
Moves report report_id to status; None if it is not stored.
Source code in src/clabe/hub/_reports.py
delete ¶
Deletes reports (rows and zips); returns how many there were.
Source code in src/clabe/hub/_reports.py
purge ¶
Deletes the reports received more than days days ago; returns how many.
Source code in src/clabe/hub/_reports.py
counts_by_rig ¶
How many reports are stored for each rig.
Source code in src/clabe/hub/_reports.py
StoredReport ¶
Bases: ReportInfo
A report the hub collected: its ReportInfo, the rig it came from, and where it is in its triage.
ZipEntry ¶
Bases: BaseModel
A file in a report's zip.
create_hub_app ¶
create_hub_app(
fleet: Fleet,
*,
token: str | None = None,
static_dir: Path | None = STATIC_DIR,
poll: bool = True,
self_url: str | None = None,
) -> FastAPI
Builds the hub's app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fleet
|
Fleet
|
The rigs to follow. |
required |
token
|
str | None
|
When set, every API call (the hub's and each rig's) must carry it. |
None
|
static_dir
|
Path | None
|
The web UI, served at |
STATIC_DIR
|
poll
|
bool
|
Whether to poll the rigs in the background while the app runs. |
True
|
self_url
|
str | None
|
Where the hub reaches itself ( |
None
|
Source code in src/clabe/hub/_app.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |