use super::{LoginHistoryError, LoginHistoryStore, O2P_LOGIN_HISTORY_RETENTION_DAYS};
pub async fn cleanup_old_login_history() -> Result<u64, LoginHistoryError> {
let days = *O2P_LOGIN_HISTORY_RETENTION_DAYS;
if days == 0 {
return Ok(0);
}
LoginHistoryStore::delete_old_entries(days).await
}
pub fn spawn_login_history_cleanup() {
tokio::spawn(async {
let mut interval = tokio::time::interval(std::time::Duration::from_secs(86400));
loop {
interval.tick().await;
match cleanup_old_login_history().await {
Ok(0) => {}
Ok(n) => tracing::info!("Deleted {n} old login history entries"),
Err(e) => tracing::error!("Login history cleanup failed: {e}"),
}
}
});
}
#[cfg(test)]
mod tests;