export an open-todos gauge and chart it on the agent dashboard
This commit is contained in:
parent
c273527219
commit
08b8eb3f73
1 changed files with 162 additions and 0 deletions
|
|
@ -376,6 +376,24 @@ impl Todos {
|
|||
Ok(any)
|
||||
}
|
||||
|
||||
/// Number of un-acked todo rows across every subsystem: the length of
|
||||
/// [`Todos::list`]`(None)`, without materialising the rows.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Propagates the sqlite query failure.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the connection mutex is poisoned.
|
||||
pub fn open_count(&self) -> Result<u64> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let n: u64 = conn.query_row("SELECT COUNT(*) FROM todos WHERE acked = 0", [], |row| {
|
||||
row.get(0)
|
||||
})?;
|
||||
Ok(n)
|
||||
}
|
||||
|
||||
/// Reap acked rows whose `acked_at` is older than `cutoff` (a unix
|
||||
/// timestamp). Called by the harness's hourly vacuum sweep
|
||||
/// (`vacuum.rs`), not on any hot path — bounds the table against acked
|
||||
|
|
@ -492,6 +510,21 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_count_follows_adds_and_acks() {
|
||||
let (_dir, s) = store();
|
||||
assert_eq!(s.open_count().unwrap(), 0);
|
||||
let (a, _) = s.upsert("bash", None, "one", None, false).unwrap();
|
||||
s.upsert("bash", None, "two", None, false).unwrap();
|
||||
s.upsert("matrix", Some("!r:x"), "three", None, false)
|
||||
.unwrap();
|
||||
assert_eq!(s.open_count().unwrap(), 3);
|
||||
s.mark_done(a).unwrap();
|
||||
assert_eq!(s.open_count().unwrap(), 2, "acked rows are not open");
|
||||
assert_eq!(s.clear("matrix", Some("!r:x")).unwrap(), 1);
|
||||
assert_eq!(s.open_count().unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_any_reflects_emptiness() {
|
||||
let (_dir, s) = store();
|
||||
|
|
|
|||
Loading…
Reference in a new issue