use crate::models::SAMLAssertionId;
use sqlx::PgPool;
use std::time::Duration;
use tracing::{error, info};
pub fn start_saml_cleanup_worker(pool: PgPool) {
tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_secs(3600));
interval.tick().await;
loop {
interval.tick().await;
match SAMLAssertionId::cleanup_expired(&pool).await {
Ok(deleted_count) => {
if deleted_count > 0 {
info!("SAML cleanup: Removed {} expired assertion IDs", deleted_count);
} else {
tracing::debug!("SAML cleanup: No expired assertion IDs to remove");
}
}
Err(e) => {
error!("SAML cleanup error: Failed to remove expired assertion IDs: {:?}", e);
}
}
}
});
info!("SAML assertion cleanup worker started (runs every hour)");
}