From e6c890e7ba24ec41963b10822043d1f5b55ebe05 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Wed, 15 Jan 2025 11:26:51 +0800 Subject: [PATCH] chore: only log exit code in mod.rs Signed-off-by: Wei Zhang --- .../src/service/background_job/db.rs | 31 ++++++++++--------- .../src/service/background_job/git.rs | 2 +- .../index_garbage_collection.rs | 6 ++-- .../src/service/background_job/mod.rs | 3 ++ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/ee/tabby-webserver/src/service/background_job/db.rs b/ee/tabby-webserver/src/service/background_job/db.rs index e420c531ec1d..e90c35fb8661 100644 --- a/ee/tabby-webserver/src/service/background_job/db.rs +++ b/ee/tabby-webserver/src/service/background_job/db.rs @@ -20,19 +20,19 @@ impl DbMaintainanceJob { context: Arc, db: DbConn, ) -> tabby_schema::Result<()> { - let mut exit_code = 0; + let mut has_error = false; if let Err(e) = db.delete_expired_token().await { - exit_code = -1; - logkit::warn!(exit_code = exit_code; "Failed to delete expired tokens: {}", e); + has_error = true; + logkit::warn!("Failed to delete expired tokens: {}", e); }; if let Err(e) = db.delete_expired_password_resets().await { - exit_code = -1; - logkit::warn!(exit_code = exit_code; "Failed to delete expired password resets: {}", e); + has_error = true; + logkit::warn!("Failed to delete expired password resets: {}", e); }; if let Err(e) = db.delete_expired_ephemeral_threads().await { - exit_code = -1; - logkit::warn!(exit_code = exit_code; "Failed to delete expired ephemeral threads: {}", e); + has_error = true; + logkit::warn!("Failed to delete expired ephemeral threads: {}", e); }; // Read all active sources @@ -47,22 +47,25 @@ impl DbMaintainanceJob { .delete_unused_source_id_read_access_policy(&active_source_ids) .await { - exit_code = -1; - logkit::warn!(exit_code = exit_code; "Failed to delete unused source id read access policy: {}", e); + has_error = true; + logkit::warn!( + "Failed to delete unused source id read access policy: {}", + e + ); }; } Err(e) => { - exit_code = -1; - logkit::warn!(exit_code = exit_code; "Failed to read active sources: {}", e); + has_error = true; + logkit::warn!("Failed to read active sources: {}", e); } } if let Err(e) = Self::data_retention(now, &db).await { - exit_code = -1; - logkit::warn!(exit_code = exit_code; "Failed to run data retention job: {}", e); + has_error = true; + logkit::warn!("Failed to run data retention job: {}", e); } - if exit_code == 0 { + if has_error { Ok(()) } else { Err(CoreError::Other(anyhow::anyhow!( diff --git a/ee/tabby-webserver/src/service/background_job/git.rs b/ee/tabby-webserver/src/service/background_job/git.rs index dca3ebcc4a0a..dca956f24d5b 100644 --- a/ee/tabby-webserver/src/service/background_job/git.rs +++ b/ee/tabby-webserver/src/service/background_job/git.rs @@ -45,7 +45,7 @@ impl SchedulerGitJob { let repositories = match git_repository.repository_list().await { Ok(repos) => repos, Err(err) => { - logkit::warn!(exit_code = -1; "Failed to list repositories: {}", err); + logkit::warn!("Failed to list repositories: {}", err); return Err(err); } }; diff --git a/ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs b/ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs index edacdcb48321..8ee9b1c3b185 100644 --- a/ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs +++ b/ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs @@ -23,7 +23,7 @@ impl IndexGarbageCollection { let sources = match context.read(None).await { Ok(sources) => sources, Err(err) => { - logkit::warn!(exit_code = -1; "Failed to list sources: {}", err); + logkit::warn!("Failed to list sources: {}", err); return Err(err); } }; @@ -34,7 +34,7 @@ impl IndexGarbageCollection { .collect::>(); if let Err(e) = run_index_garbage_collection(sources) { - logkit::warn!(exit_code = -1; "Failed to run index garbage collection: {}", e); + logkit::warn!("Failed to run index garbage collection: {}", e); return Err(e.into()); } @@ -42,7 +42,7 @@ impl IndexGarbageCollection { let repositories = match repository.list_all_code_repository().await { Ok(repos) => repos, Err(err) => { - logkit::warn!(exit_code = -1; "Failed to list repositories: {}", err); + logkit::warn!("Failed to list repositories: {}", err); return Err(err); } }; diff --git a/ee/tabby-webserver/src/service/background_job/mod.rs b/ee/tabby-webserver/src/service/background_job/mod.rs index 18598bf7e8d3..81cb62e57802 100644 --- a/ee/tabby-webserver/src/service/background_job/mod.rs +++ b/ee/tabby-webserver/src/service/background_job/mod.rs @@ -265,7 +265,10 @@ async fn run_job( let logger = JobLogger::new(db.clone(), job_id); if let Err(err) = job_fn().await { + logkit::warn!(exit_code = 1; "Job failed {}", err); notify_job_error!(notification_service, err, job_name, job_id); + } else { + logkit::info!(exit_code = 0; "Job completed successfully"); } logger.finalize().await; }