Skip to content

Commit

Permalink
fix(scheduler): Panic when now jobs fail (#1656)
Browse files Browse the repository at this point in the history
* fix(scheduler): Panic when now jobs fail

* Bail instead of panic

* Apply suggestions
  • Loading branch information
boxbeam authored Mar 19, 2024
1 parent 409bdb2 commit 6c5f4f8
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions crates/tabby-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use tracing::{error, info, warn};
pub async fn scheduler<T: RepositoryAccess + 'static>(now: bool, access: T) -> Result<()> {
if now {
let repositories = access.list_repositories().await?;
job_sync(&repositories);
job_index(&repositories);
job_sync(&repositories)?;
job_index(&repositories)?;
} else {
let access = Arc::new(access);
let scheduler = JobScheduler::new().await?;
Expand All @@ -37,8 +37,12 @@ pub async fn scheduler<T: RepositoryAccess + 'static>(now: bool, access: T) -> R
.list_repositories()
.await
.expect("Must be able to retrieve repositories for sync");
job_sync(&repositories);
job_index(&repositories);
if let Err(e) = job_sync(&repositories) {
error!("{e}");
}
if let Err(e) = job_index(&repositories) {
error!("{e}")
}
})
})?)
.await?;
Expand All @@ -53,25 +57,26 @@ pub async fn scheduler<T: RepositoryAccess + 'static>(now: bool, access: T) -> R
Ok(())
}

fn job_index(repositories: &[RepositoryConfig]) {
fn job_index(repositories: &[RepositoryConfig]) -> Result<()> {
println!("Indexing repositories...");
let ret = index::index_repositories(repositories);
if let Err(err) = ret {
error!("Failed to index repositories, err: '{}'", err);
return Err(err.context("Failed to index repositories"));
}
Ok(())
}

fn job_sync(repositories: &[RepositoryConfig]) {
fn job_sync(repositories: &[RepositoryConfig]) -> Result<()> {
println!("Syncing {} repositories...", repositories.len());
let ret = repository::sync_repositories(repositories);
if let Err(err) = ret {
error!("Failed to sync repositories, err: '{}'", err);
return;
return Err(err.context("Failed to sync repositories"));
}

println!("Building dataset...");
let ret = dataset::create_dataset(repositories);
if let Err(err) = ret {
error!("Failed to build dataset, err: '{}'", err);
return Err(err.context("Failed to build dataset"));
}
Ok(())
}

0 comments on commit 6c5f4f8

Please sign in to comment.