dm_database_sqllog2db/cli/watch/
state.rs1use crate::error::ErrorStats;
4use std::collections::HashMap;
5use std::path::PathBuf;
6use std::time::{Duration, Instant};
7
8pub(super) const DEBOUNCE_WINDOW: Duration = Duration::from_millis(500);
12
13pub(super) const STATUS_REFRESH_INTERVAL: Duration = Duration::from_millis(200);
16
17#[derive(Debug)]
19pub struct WatchLoopState {
20 pub(super) last_trigger_at: Option<Instant>,
21 pub(super) last_status_refresh: Instant,
22 pub(super) debounce_map: HashMap<PathBuf, Instant>,
23 pub(super) total_stats: ErrorStats,
24 pub(super) trigger_count: u64,
25 pub(super) file_offsets: HashMap<PathBuf, u64>,
27 pub(super) sqlite_db_url: Option<String>,
29}
30
31impl WatchLoopState {
32 #[must_use]
34 pub fn new(init_offsets: HashMap<PathBuf, u64>, sqlite_db_url: Option<String>) -> Self {
35 Self {
36 last_trigger_at: None,
37 last_status_refresh: Instant::now(),
38 debounce_map: HashMap::new(),
39 total_stats: ErrorStats::default(),
40 trigger_count: 0u64,
41 file_offsets: init_offsets,
42 sqlite_db_url,
43 }
44 }
45
46 #[must_use]
48 pub fn trigger_count(&self) -> u64 {
49 self.trigger_count
50 }
51
52 #[must_use]
54 pub fn total_stats(&self) -> &ErrorStats {
55 &self.total_stats
56 }
57
58 #[must_use]
60 #[allow(dead_code)]
61 pub fn file_offsets(&self) -> &HashMap<PathBuf, u64> {
62 &self.file_offsets
63 }
64}