pitchfork_cli/log_store/
mod.rs1use crate::Result;
2use crate::daemon_id::DaemonId;
3use chrono::{DateTime, Local};
4
5#[derive(Debug, Clone)]
7pub struct LogEntry {
8 pub id: i64,
9 pub daemon_id: String,
10 pub timestamp: DateTime<Local>,
11 pub message: String,
12}
13
14#[derive(Debug, Clone, Default)]
16pub struct LogQuery {
17 pub daemon_ids: Vec<String>,
18 pub from: Option<DateTime<Local>>,
19 pub to: Option<DateTime<Local>>,
20 pub limit: Option<usize>,
21 pub order_desc: bool,
22 pub after_id: Option<i64>,
23}
24
25#[derive(Debug, Clone, Copy)]
27pub struct RetentionPolicy {
28 pub age: Option<chrono::Duration>,
30 pub count: Option<u64>,
32}
33
34impl RetentionPolicy {
35 #[allow(dead_code)]
36 pub fn is_none(&self) -> bool {
37 self.age.is_none() && self.count.is_none()
38 }
39}
40
41#[derive(Debug, Clone)]
43pub struct ArchiveHook {
44 pub command: String,
46 pub batch_size: usize,
48}
49
50impl ArchiveHook {
51 pub fn is_enabled(&self) -> bool {
53 !self.command.trim().is_empty()
54 }
55}
56
57pub trait LogStore: Send + Sync {
59 fn append(&self, daemon_id: &DaemonId, message: &str) -> Result<()>;
61
62 fn query(&self, opts: &LogQuery) -> Result<Vec<LogEntry>>;
64
65 fn tail(&self, daemon_id: &DaemonId, after_id: Option<i64>) -> Result<Vec<LogEntry>>;
69
70 fn clear(&self, daemon_ids: &[DaemonId]) -> Result<()>;
72
73 fn apply_retention(
80 &self,
81 policy: &RetentionPolicy,
82 excluded_daemon_ids: &[DaemonId],
83 archive_hook: Option<&ArchiveHook>,
84 ) -> Result<u64> {
85 let _ = (policy, excluded_daemon_ids, archive_hook);
86 Ok(0)
87 }
88
89 fn apply_retention_for_daemon(
91 &self,
92 daemon_id: &DaemonId,
93 policy: &RetentionPolicy,
94 archive_hook: Option<&ArchiveHook>,
95 ) -> Result<u64> {
96 let _ = (daemon_id, policy, archive_hook);
97 Ok(0)
98 }
99
100 fn list_daemon_ids(&self) -> Result<Vec<String>>;
102
103 fn last_clear_generation(&self, daemon_id: &DaemonId) -> Result<Option<u64>> {
107 let _ = daemon_id;
108 Ok(None)
109 }
110}
111
112pub mod sqlite;