From e272ca296bc1749865b284aeb66d39b5efebf56e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 13 Apr 2024 06:54:19 +0100 Subject: [PATCH] fix(actor/repo): always reschedule to validate repos If validate repos saw anything unexpected it would stop and not schedule a re-validation. --- src/server/actors/repo/branch.rs | 36 ++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/server/actors/repo/branch.rs b/src/server/actors/repo/branch.rs index 6341d16..e1bcf6a 100644 --- a/src/server/actors/repo/branch.rs +++ b/src/server/actors/repo/branch.rs @@ -29,35 +29,34 @@ pub async fn validate_positions( Ok(commit_histories) => commit_histories, Err(err) => { error!(?err, "Failed to get commit histories"); + revalidate_positions(addr).await; return; } }; let Some(main) = commit_histories.main.first().cloned() else { warn!("No commits on main branch '{}'", config.branches().main()); + revalidate_positions(addr).await; return; }; // verify that next is an ancestor of dev, and force update to it main if it isn't let Some(next) = commit_histories.next.first().cloned() else { warn!("No commits on next branch '{}", config.branches().next()); + revalidate_positions(addr).await; return; }; let next_is_ancestor_of_dev = commit_histories.dev.iter().any(|dev| dev == &next); if !next_is_ancestor_of_dev { info!("Next is not an ancestor of dev - resetting next to main"); - - if git - .reset( - &config.branches().next(), - main.into(), - ResetForce::Force(next.into()), - &repo_details, - ) - .is_ok() - { - // TODO : (#18) sleep and restart while we don't have webhooks - tokio::time::sleep(std::time::Duration::from_secs(10)).await; - addr.do_send(super::ValidateRepo) + let reset = git.reset( + &config.branches().next(), + main.into(), + ResetForce::Force(next.into()), + &repo_details, + ); + if let Err(err) = reset { + warn!(?err, "Failed"); } + revalidate_positions(addr).await; return; } @@ -72,10 +71,12 @@ pub async fn validate_positions( config.branches().main(), config.branches().next() ); + revalidate_positions(addr).await; return; } let Some(next) = next_commits.first().cloned() else { warn!("No commits on next branch '{}'", config.branches().next()); + revalidate_positions(addr).await; return; }; let dev_has_next = commit_histories @@ -88,6 +89,7 @@ pub async fn validate_positions( config.branches().dev(), config.branches().next() ); + revalidate_positions(addr).await; return; // dev is not based on next } let dev_has_main = commit_histories.dev.iter().any(|commit| commit == &main); @@ -97,10 +99,12 @@ pub async fn validate_positions( config.branches().dev(), config.branches().main() ); + revalidate_positions(addr).await; return; } let Some(dev) = commit_histories.dev.first().cloned() else { warn!("No commits on dev branch '{}'", config.branches().dev()); + revalidate_positions(addr).await; return; }; addr.do_send(StartMonitoring { @@ -111,6 +115,12 @@ pub async fn validate_positions( }); } +async fn revalidate_positions(addr: Addr) { + // TODO : (#18) sleep and restart while we don't have webhooks + tokio::time::sleep(std::time::Duration::from_secs(10)).await; + addr.do_send(ValidateRepo) +} + // advance next to the next commit towards the head of the dev branch #[tracing::instrument(fields(next), skip_all)] pub async fn advance_next(