Skip to content

Commit

Permalink
chore: return error directly if meet one for now
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Jan 8, 2025
1 parent 6f9f7fc commit 32c0733
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions ee/tabby-webserver/src/service/background_job/db.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::sync::Arc;

use anyhow::Context;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use tabby_db::DbConn;
use tabby_schema::context::ContextService;
use tracing::warn;

use super::helper::Job;

Expand Down Expand Up @@ -37,24 +37,20 @@ impl DbMaintainanceJob {
db.delete_unused_source_id_read_access_policy(&active_source_ids)
.await?;

Self::data_retention(now, &db).await;
Self::data_retention(now, &db).await?;
Ok(())
}

Check warning on line 42 in ee/tabby-webserver/src/service/background_job/db.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/db.rs#L40-L42

Added lines #L40 - L42 were not covered by tests

async fn data_retention(now: DateTime<Utc>, db: &DbConn) {
if let Err(e) = db.delete_job_run_before_three_months(now).await {
warn!(
"Failed to clean up and retain only the last 3 months of jobs: {:?}",
e
);
}
async fn data_retention(now: DateTime<Utc>, db: &DbConn) -> tabby_schema::Result<()> {
db.delete_job_run_before_three_months(now)
.await
.context("Failed to clean up and retain only the last 3 months of jobs")?;

if let Err(e) = db.delete_user_events_before_three_months(now).await {
warn!(
"Failed to clean up and retain only the last 3 months of user events: {:?}",
e
);
}
db.delete_user_events_before_three_months(now)
.await
.context("Failed to clean up and retain only the last 3 months of user events")?;

Ok(())
}
}

Expand Down Expand Up @@ -110,7 +106,7 @@ mod tests {
.unwrap();
assert_eq!(events.len(), 1);

DbMaintainanceJob::data_retention(now, &db).await;
DbMaintainanceJob::data_retention(now, &db).await.unwrap();

let events = db
.list_user_events(
Expand Down Expand Up @@ -172,7 +168,7 @@ mod tests {
.unwrap();
assert_eq!(events.len(), 1);

DbMaintainanceJob::data_retention(now, &db).await;
DbMaintainanceJob::data_retention(now, &db).await.unwrap();

let events = db
.list_user_events(
Expand Down

0 comments on commit 32c0733

Please sign in to comment.