refactor: single now_unix in hive_sh4re::wire_time

replaces 15 per-module copies (now_unix/now_secs) across hive-c0re and
hive-ag3nt; wire_time already owns the epoch-seconds convention
This commit is contained in:
müde 2026-07-06 21:58:32 +02:00
commit c84028ddcf
16 changed files with 45 additions and 125 deletions

View file

@ -19,6 +19,7 @@ use std::sync::Mutex;
use anyhow::{Context, Result};
use rusqlite::{Connection, OptionalExtension, params};
use hive_sh4re::wire_time::now_unix;
const SCHEMA: &str = "
CREATE TABLE IF NOT EXISTS agent_power (
@ -128,7 +129,7 @@ impl PowerStore {
conn.execute(
"INSERT INTO agent_power (agent, wanted, updated_at) VALUES (?1, ?2, ?3)
ON CONFLICT(agent) DO UPDATE SET wanted = ?2, updated_at = ?3",
params![agent, wanted.as_str(), now_secs()],
params![agent, wanted.as_str(), now_unix()],
)
.context("upsert agent_power")?;
Ok(())
@ -157,13 +158,6 @@ impl PowerStore {
}
}
fn now_secs() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.ok()
.and_then(|d| i64::try_from(d.as_secs()).ok())
.unwrap_or(0)
}
#[cfg(test)]
mod tests {