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    pub fn new(db_pool: &DbPool) -> anyhow::Result<Self> {
14        Ok(Self {
15            repo: LoggingRepository::new(db_pool)?,
16        })
17    }
18
19    pub async fn get_recent_logs(&self, limit: i64) -> Result<Vec<LogEntry>, LoggingError> {
20        self.repo.get_recent_logs(limit).await
21    }
22
23    pub async fn cleanup_old_logs(&self, older_than: DateTime<Utc>) -> Result<u64, LoggingError> {
24        self.repo.cleanup_old_logs(older_than).await
25    }
26
27    pub async fn count_logs_before(&self, cutoff: DateTime<Utc>) -> Result<u64, LoggingError> {
28        self.repo.count_logs_before(cutoff).await
29    }
30
31    pub async fn clear_all_logs(&self) -> Result<u64, LoggingError> {
32        self.repo.clear_all_logs().await
33    }
34
35    pub const fn vacuum() {}
36}