hive-agent: finish chrono-clock migration on remaining call sites
This commit is contained in:
parent
2122e23d81
commit
f4a35786b1
10 changed files with 63 additions and 47 deletions
|
|
@ -32,7 +32,8 @@ use std::path::Path;
|
|||
use std::sync::Mutex;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use hive_sh4re::wire_time::now_unix;
|
||||
use chrono::{DateTime, Utc};
|
||||
use hive_sh4re::wire_time;
|
||||
use rusqlite::{Connection, params};
|
||||
|
||||
/// SQL bootstrap. `CREATE TABLE IF NOT EXISTS` so first-boot agents and
|
||||
|
|
@ -66,8 +67,8 @@ const MIGRATIONS: &[&str] = &[
|
|||
"ALTER TABLE todos ADD COLUMN acked_at INTEGER",
|
||||
];
|
||||
|
||||
/// One dynamic, subsystem-pushed todo. Timestamps are unix seconds; the
|
||||
/// consumer derives `age_seconds` from `updated_at`.
|
||||
/// One dynamic, subsystem-pushed todo. The consumer derives `age_seconds`
|
||||
/// from `updated_at`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Todo {
|
||||
pub id: i64,
|
||||
|
|
@ -80,7 +81,7 @@ pub struct Todo {
|
|||
pub summary: String,
|
||||
/// Optional free-text provenance (e.g. the room name / task label).
|
||||
pub source: Option<String>,
|
||||
pub updated_at: i64,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// The harness-local todo store. Cheap to share behind an `Arc`; the inner
|
||||
|
|
@ -144,7 +145,7 @@ impl Todos {
|
|||
source: Option<&str>,
|
||||
) -> Result<(i64, bool)> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let now = now_unix();
|
||||
let now = Utc::now().timestamp();
|
||||
let existing: Option<(i64, String, Option<String>)> = if key.is_some() {
|
||||
conn.query_row(
|
||||
"SELECT id, summary, source FROM todos \
|
||||
|
|
@ -239,7 +240,7 @@ impl Todos {
|
|||
let conn = self.conn.lock().unwrap();
|
||||
let n = conn.execute(
|
||||
"UPDATE todos SET acked = 1, acked_at = ?1 WHERE id = ?2 AND acked = 0",
|
||||
params![now_unix(), id],
|
||||
params![Utc::now().timestamp(), id],
|
||||
)?;
|
||||
Ok(n)
|
||||
}
|
||||
|
|
@ -266,13 +267,14 @@ impl Todos {
|
|||
)?;
|
||||
let rows = stmt
|
||||
.query_map(params![subsystem], |row| {
|
||||
let updated_at_secs: i64 = row.get(5)?;
|
||||
Ok(Todo {
|
||||
id: row.get(0)?,
|
||||
subsystem: row.get(1)?,
|
||||
subsystem_key: row.get(2)?,
|
||||
summary: row.get(3)?,
|
||||
source: row.get(4)?,
|
||||
updated_at: row.get(5)?,
|
||||
updated_at: wire_time::from_secs(updated_at_secs),
|
||||
})
|
||||
})?
|
||||
.collect::<rusqlite::Result<Vec<_>>>()?;
|
||||
|
|
@ -491,12 +493,12 @@ mod tests {
|
|||
let conn = s.conn.lock().unwrap();
|
||||
conn.execute(
|
||||
"UPDATE todos SET acked_at = ?1 WHERE id = ?2",
|
||||
params![now_unix() - 1000, old_id],
|
||||
params![Utc::now().timestamp() - 1000, old_id],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let removed = s.reap_acked(now_unix() - 500).unwrap();
|
||||
let removed = s.reap_acked(Utc::now().timestamp() - 500).unwrap();
|
||||
assert_eq!(removed, 1, "only the backdated row is past the cutoff");
|
||||
|
||||
let conn = Connection::open(dir.path().join("todos.sqlite")).unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue