diff --git a/ee/tabby-webserver/src/service/background_job/db.rs b/ee/tabby-webserver/src/service/background_job/db.rs index 10b6128b4666..fb3dfd886cb5 100644 --- a/ee/tabby-webserver/src/service/background_job/db.rs +++ b/ee/tabby-webserver/src/service/background_job/db.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use tabby_db::DbConn; -use tabby_schema::context::ContextService; +use tabby_schema::{context::ContextService, CoreError}; use super::helper::Job; @@ -20,21 +20,48 @@ impl DbMaintainanceJob { context: Arc, db: DbConn, ) -> tabby_schema::Result<()> { - db.delete_expired_token().await?; - db.delete_expired_password_resets().await?; - db.delete_expired_ephemeral_threads().await?; + let mut errors = vec![]; + + if let Err(e) = db.delete_expired_token().await { + errors.push(format!("Failed to delete expired token: {}", e)); + }; + if let Err(e) = db.delete_expired_password_resets().await { + errors.push(format!("Failed to delete expired password resets: {}", e)); + }; + if let Err(e) = db.delete_expired_ephemeral_threads().await { + errors.push(format!("Failed to delete expired ephemeral threads: {}", e)); + }; // Read all active sources - let active_source_ids = context - .read(None) - .await? - .sources - .into_iter() - .map(|x| x.source_id()) - .collect::>(); - - db.delete_unused_source_id_read_access_policy(&active_source_ids) - .await?; - Ok(()) + match context.read(None).await { + Ok(info) => { + let active_source_ids = info + .sources + .into_iter() + .map(|x| x.source_id()) + .collect::>(); + if let Err(e) = db + .delete_unused_source_id_read_access_policy(&active_source_ids) + .await + { + errors.push(format!( + "Failed to delete unused source id read access policy: {}", + e + )); + }; + } + Err(e) => { + errors.push(format!("Failed to read active sources: {}", e)); + } + } + + if errors.is_empty() { + Ok(()) + } else { + Err(CoreError::Other(anyhow::anyhow!( + "Failed to run db maintenance job:\n{}", + errors.join(";\n") + ))) + } } }