systemprompt_logging/services/
maintenance.rs1use chrono::{DateTime, Utc};
2use systemprompt_database::DbPool;
3
4use crate::models::{LogEntry, LogFilter, 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 get_filtered_logs(
24 &self,
25 filter: &LogFilter,
26 ) -> Result<(Vec<LogEntry>, i64), LoggingError> {
27 self.repo.get_logs_paginated(filter).await
28 }
29
30 pub async fn cleanup_old_logs(&self, older_than: DateTime<Utc>) -> Result<u64, LoggingError> {
31 self.repo.cleanup_old_logs(older_than).await
32 }
33
34 pub async fn count_logs_before(&self, cutoff: DateTime<Utc>) -> Result<u64, LoggingError> {
35 self.repo.count_logs_before(cutoff).await
36 }
37
38 pub async fn clear_all_logs(&self) -> Result<u64, LoggingError> {
39 self.repo.clear_all_logs().await
40 }
41
42 pub const fn vacuum() {}
43}