Skip to main content

systemprompt_logging/services/
maintenance.rs

1use chrono::{DateTime, Utc};
2use systemprompt_database::DbPool;
3
4use crate::models::{LogEntry, LoggingError};
5use crate::repository::LoggingRepository;
6
7#[derive(Clone, Debug)]
8pub struct LoggingMaintenanceService {
9    repo: LoggingRepository,
10}
11
12impl LoggingMaintenanceService {
13    #[must_use]
14    #[allow(clippy::missing_const_for_fn)]
15    pub fn new(db_pool: DbPool) -> Self {
16        Self {
17            repo: LoggingRepository::new(db_pool),
18        }
19    }
20
21    pub async fn get_recent_logs(&self, limit: i64) -> Result<Vec<LogEntry>, LoggingError> {
22        self.repo.get_recent_logs(limit).await
23    }
24
25    pub async fn cleanup_old_logs(&self, older_than: DateTime<Utc>) -> Result<u64, LoggingError> {
26        self.repo.cleanup_old_logs(older_than).await
27    }
28
29    pub async fn count_logs_before(&self, cutoff: DateTime<Utc>) -> Result<u64, LoggingError> {
30        self.repo.count_logs_before(cutoff).await
31    }
32
33    pub async fn clear_all_logs(&self) -> Result<u64, LoggingError> {
34        self.repo.clear_all_logs().await
35    }
36
37    pub const fn vacuum() {}
38}