From a87241c3d107f168d097b2a4505ddaf9043b0e8a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 30 Aug 2024 20:58:38 +0100 Subject: [PATCH] fix(repo): avoid blocking threads when pausing --- crates/cli/src/repo/handlers/advance_next.rs | 2 +- crates/cli/src/repo/handlers/receive_ci_status.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/cli/src/repo/handlers/advance_next.rs b/crates/cli/src/repo/handlers/advance_next.rs index e8f773c..ad3d2b5 100644 --- a/crates/cli/src/repo/handlers/advance_next.rs +++ b/crates/cli/src/repo/handlers/advance_next.rs @@ -53,7 +53,7 @@ impl Handler for RepoActor { let sleep_duration = self.sleep_duration; let log = self.log.clone(); async move { - std::thread::sleep(sleep_duration); + actix_rt::time::sleep(sleep_duration).await; do_send(&addr, ValidateRepo::new(message_token), log.as_ref()); } .in_current_span() diff --git a/crates/cli/src/repo/handlers/receive_ci_status.rs b/crates/cli/src/repo/handlers/receive_ci_status.rs index 6d65299..cc1465f 100644 --- a/crates/cli/src/repo/handlers/receive_ci_status.rs +++ b/crates/cli/src/repo/handlers/receive_ci_status.rs @@ -2,7 +2,7 @@ use actix::prelude::*; use git_next_core::git::{forge::commit::Status, graph, UserNotification}; -use tracing::{debug, Instrument as _}; +use tracing::{debug, Instrument}; use crate::{ repo::{ @@ -37,8 +37,14 @@ impl Handler for RepoActor { do_send(&addr, AdvanceMain::new(next), self.log.as_ref()); } Status::Pending => { - std::thread::sleep(sleep_duration); - do_send(&addr, ValidateRepo::new(message_token), self.log.as_ref()); + let log = self.log.clone(); + async move { + actix_rt::time::sleep(sleep_duration).await; + do_send(&addr, ValidateRepo::new(message_token), log.as_ref()); + } + .in_current_span() + .into_actor(self) + .wait(ctx); } Status::Fail => { tracing::warn!("Checks have failed");