crates/nornir-warehouse-embed/examples/scan_build_tables.rs
//! **"Is the build-record store EMPTY, or could I not READ it?"** — from a shell.
//!
//! ⚒ Build Thing came up empty four times, and three of those were misdiagnosed
//! because nothing could answer that question without opening a UI. This example is
//! the shell-side twin of the pane's ⟳ Build records strip: it scans
//! `build_provenance` + `build_info` over the SAME thin `Warehouse.Scan` seam and
//! prints one of two structurally different answers — never a bare "0".
//!
//! ```text
//! # through nornir directly
//! NORNIR_SERVER=http://127.0.0.1:7878 NORNIR_WORKSPACE=nordisk \
//! cargo run -p nornir-warehouse-embed --example scan_build_tables
//!
//! # through the dwarves HOST's proxy (the path the UI actually takes)
//! NORNIR_SERVER=http://127.0.0.1:7900 NORNIR_WORKSPACE=nordisk …
//! ```
//!
//! `NORNIR_SERVER_TOKEN` supplies the bearer (empty ⇒ open).
fn main() {
let endpoint =
std::env::var("NORNIR_SERVER").unwrap_or_else(|_| "http://127.0.0.1:7878".into());
let token = std::env::var("NORNIR_SERVER_TOKEN").unwrap_or_default();
let workspace = std::env::var("NORNIR_WORKSPACE").unwrap_or_else(|_| "nordisk".into());
println!("store: {endpoint} · workspace `{workspace}`");
for table in ["build_provenance", "build_info"] {
match nornir_warehouse_embed::scan_warehouse_table(&endpoint, &token, &workspace, table, 0)
{
Ok(scan) if scan.rows.is_empty() => println!(
" {table}: READ OK — HOLDS NONE (the store is fine; nothing has produced \
a build record here)"
),
Ok(scan) => {
println!(
" {table}: READ OK — {} row(s) {:?}",
scan.rows.len(),
scan.columns
);
for row in scan.rows.iter().take(3) {
let cells: Vec<String> =
row.iter().map(|c| c.chars().take(60).collect()).collect();
println!(" {cells:?}");
}
}
// NOT "0 rows" — the question was never answered.
Err(e) => println!(" {table}: UNREADABLE — {e} [dwarves-buildthing-11]"),
}
}
}