Skip to main content

systemprompt_analytics/services/
session_cleanup.rs

1//! Inactive-session cleanup service.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use crate::Result;
7use systemprompt_database::DbPool;
8
9use crate::repository::SessionRepository;
10
11#[derive(Clone, Debug)]
12pub struct SessionCleanupService {
13    session_repo: SessionRepository,
14}
15
16impl SessionCleanupService {
17    pub fn new(db_pool: &DbPool) -> Result<Self> {
18        Ok(Self {
19            session_repo: SessionRepository::new(db_pool)?,
20        })
21    }
22
23    pub async fn cleanup_inactive_sessions(&self, inactive_hours: i32) -> Result<u64> {
24        self.session_repo.cleanup_inactive(inactive_hours).await
25    }
26}