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
|
|
@ -11,11 +11,11 @@ use std::collections::{HashMap, HashSet};
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use chrono::Utc;
|
||||
use rusqlite::{Connection, OpenFlags};
|
||||
use serde::Serialize;
|
||||
|
||||
use hive_sh4re::ReminderStats;
|
||||
use hive_sh4re::wire_time::now_unix;
|
||||
|
||||
/// Window param accepted by `/api/stats?window=`. Each maps to a
|
||||
/// total span + the bucket width used to roll up trend series.
|
||||
|
|
@ -225,7 +225,7 @@ fn default_path() -> PathBuf {
|
|||
}
|
||||
|
||||
fn empty_snapshot(window: Window) -> Snapshot {
|
||||
let now = now_unix();
|
||||
let now = Utc::now().timestamp();
|
||||
let from = now - window.span_secs();
|
||||
let buckets = fill_buckets(from, now, window.bucket_secs(), &HashMap::new());
|
||||
Snapshot {
|
||||
|
|
@ -305,7 +305,7 @@ fn snapshot(path: &Path, window: Window) -> Result<Snapshot> {
|
|||
// and blanks the whole stats page. Wait out the brief write instead.
|
||||
conn.busy_timeout(std::time::Duration::from_millis(500))
|
||||
.with_context(|| format!("set busy_timeout on {}", path.display()))?;
|
||||
let now = now_unix();
|
||||
let now = Utc::now().timestamp();
|
||||
// Fixed windows look back a constant span; `all` starts at the earliest
|
||||
// recorded turn and sizes its buckets adaptively from that span.
|
||||
let (from, bucket_secs) = match window {
|
||||
|
|
@ -677,7 +677,7 @@ mod tests {
|
|||
fn snapshot_aggregates_rows() {
|
||||
let db = tmp_db();
|
||||
let _ = std::fs::remove_file(&db);
|
||||
let now = now_unix();
|
||||
let now = Utc::now().timestamp();
|
||||
seed_db(
|
||||
&db,
|
||||
&[
|
||||
|
|
@ -766,7 +766,17 @@ mod tests {
|
|||
fn bash_breakdown_empty_without_table() {
|
||||
let db = tmp_db();
|
||||
let _ = std::fs::remove_file(&db);
|
||||
seed_db(&db, &[(now_unix() - 100, 1000, "opus", "recv", "ok", "{}")]);
|
||||
seed_db(
|
||||
&db,
|
||||
&[(
|
||||
Utc::now().timestamp() - 100,
|
||||
1000,
|
||||
"opus",
|
||||
"recv",
|
||||
"ok",
|
||||
"{}",
|
||||
)],
|
||||
);
|
||||
let s = snapshot(&db, Window::Day).unwrap();
|
||||
assert!(s.bash_breakdown.is_empty());
|
||||
}
|
||||
|
|
@ -778,7 +788,7 @@ mod tests {
|
|||
let db = tmp_db();
|
||||
let _ = std::fs::remove_file(&db);
|
||||
seed_db(&db, &[]);
|
||||
let now = now_unix();
|
||||
let now = Utc::now().timestamp();
|
||||
let conn = Connection::open(&db).unwrap();
|
||||
conn.execute_batch("CREATE TABLE bash_commands (ts INTEGER NOT NULL, head TEXT NOT NULL);")
|
||||
.unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue