Skip to content

Commit

Permalink
chore: only log exit code in mod.rs
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Jan 15, 2025
1 parent a6a7c34 commit e6c890e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
31 changes: 17 additions & 14 deletions ee/tabby-webserver/src/service/background_job/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ impl DbMaintainanceJob {
context: Arc<dyn ContextService>,
db: DbConn,
) -> tabby_schema::Result<()> {
let mut exit_code = 0;
let mut has_error = false;

Check warning on line 23 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#L23

Added line #L23 was not covered by tests

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);

Check warning on line 27 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#L26-L27

Added lines #L26 - L27 were not covered by tests
};
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);

Check warning on line 31 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#L30-L31

Added lines #L30 - L31 were not covered by tests
};
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);

Check warning on line 35 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#L34-L35

Added lines #L34 - L35 were not covered by tests
};

// Read all active sources
Expand All @@ -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!(

Check warning on line 51 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#L50-L51

Added lines #L50 - L51 were not covered by tests
"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);

Check warning on line 59 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#L58-L59

Added lines #L58 - L59 were not covered by tests
}
}

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);

Check warning on line 65 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#L64-L65

Added lines #L64 - L65 were not covered by tests
}

if exit_code == 0 {
if has_error {

Check warning on line 68 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#L68

Added line #L68 was not covered by tests
Ok(())
} else {
Err(CoreError::Other(anyhow::anyhow!(
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/service/background_job/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 49 in ee/tabby-webserver/src/service/background_job/git.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/git.rs#L45-L49

Added lines #L45 - L49 were not covered by tests
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 27 in ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs#L23-L27

Added lines #L23 - L27 were not covered by tests
}
};
Expand All @@ -34,15 +34,15 @@ impl IndexGarbageCollection {
.collect::<Vec<_>>();

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());
}

Check warning on line 39 in ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs#L36-L39

Added lines #L36 - L39 were not covered by tests

// Run garbage collection on the code repositories (cloned directories)
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);

Check warning on line 46 in ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/index_garbage_collection.rs#L42-L46

Added lines #L42 - L46 were not covered by tests
}
};
Expand Down
3 changes: 3 additions & 0 deletions ee/tabby-webserver/src/service/background_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ async fn run_job<F, Fut>(

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);

Check warning on line 269 in ee/tabby-webserver/src/service/background_job/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/mod.rs#L266-L269

Added lines #L266 - L269 were not covered by tests
} else {
logkit::info!(exit_code = 0; "Job completed successfully");

Check warning on line 271 in ee/tabby-webserver/src/service/background_job/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/mod.rs#L271

Added line #L271 was not covered by tests
}
logger.finalize().await;
}

Check warning on line 274 in ee/tabby-webserver/src/service/background_job/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/mod.rs#L273-L274

Added lines #L273 - L274 were not covered by tests

0 comments on commit e6c890e

Please sign in to comment.