Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hydro_deploy): improve progress UX by collapsing nested groups #1411

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions hydro_deploy/core/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Deployment {
pub async fn deploy(&mut self) -> Result<()> {
self.services.retain(|weak| weak.strong_count() > 0);

progress::ProgressTracker::with_group("deploy", None, || async {
progress::ProgressTracker::with_group("deploy", Some(3), || async {
let mut resource_batch = super::ResourceBatch::new();

for service in self.services.iter().filter_map(Weak::upgrade) {
Expand All @@ -72,7 +72,7 @@ impl Deployment {
}

let resource_result = Arc::new(
progress::ProgressTracker::with_group("provision", None, || async {
progress::ProgressTracker::with_group("provision", Some(1), || async {
resource_batch
.provision(&mut self.resource_pool, self.last_resource_result.clone())
.await
Expand All @@ -85,12 +85,16 @@ impl Deployment {
host.provision(&resource_result);
}

progress::ProgressTracker::with_group("deploy", None, || {
let services_future = self
.services
let upgraded_services = self
.services
.iter()
.filter_map(Weak::upgrade)
.collect::<Vec<_>>();

progress::ProgressTracker::with_group("prepare", Some(upgraded_services.len()), || {
let services_future = upgraded_services
.iter()
.filter_map(Weak::upgrade)
.map(|service: Arc<RwLock<dyn Service>>| {
.map(|service: &Arc<RwLock<dyn Service>>| {
let resource_result = &resource_result;
async move { service.write().await.deploy(resource_result).await }
})
Expand All @@ -102,13 +106,14 @@ impl Deployment {
})
.await?;

progress::ProgressTracker::with_group("ready", None, || {
let all_services_ready = self.services.iter().filter_map(Weak::upgrade).map(
|service: Arc<RwLock<dyn Service>>| async move {
service.write().await.ready().await?;
Ok(()) as Result<()>
},
);
progress::ProgressTracker::with_group("ready", Some(upgraded_services.len()), || {
let all_services_ready =
upgraded_services
.iter()
.map(|service: &Arc<RwLock<dyn Service>>| async move {
service.write().await.ready().await?;
Ok(()) as Result<()>
});

futures::future::try_join_all(all_services_ready)
})
Expand Down
2 changes: 1 addition & 1 deletion hydro_deploy/core/src/hydroflow_crate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub async fn build_crate_memoized(params: BuildParams) -> Result<&'static BuildO
.get_or_init(MemoMap::new)
.get_or_insert(&params, Default::default)
.get_or_try_init(move || {
ProgressTracker::rich_leaf("build".to_string(), move |_, set_msg| async move {
ProgressTracker::rich_leaf("build", move |set_msg| async move {
tokio::task::spawn_blocking(move || {
let mut command = Command::new("cargo");
command.args(["build"]);
Expand Down
15 changes: 6 additions & 9 deletions hydro_deploy/core/src/hydroflow_crate/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ impl Service for HydroflowCrateService {
}

ProgressTracker::with_group(
&self
.display_id
self.display_id
.clone()
.unwrap_or_else(|| format!("service/{}", self.id)),
None,
|| async {
let built = self.build().await?;
let built = ProgressTracker::leaf("build", self.build()).await?;

let host = &self.on;
let launched = host.provision(resource_result);
Expand All @@ -223,8 +222,7 @@ impl Service for HydroflowCrateService {
}

ProgressTracker::with_group(
&self
.display_id
self.display_id
.clone()
.unwrap_or_else(|| format!("service/{}", self.id)),
None,
Expand Down Expand Up @@ -259,7 +257,7 @@ impl Service for HydroflowCrateService {
binary.stdin().send(format!("{formatted_bind_config}\n"))?;

let ready_line = ProgressTracker::leaf(
"waiting for ready".to_string(),
"waiting for ready",
tokio::time::timeout(Duration::from_secs(60), stdout_receiver),
)
.await??;
Expand Down Expand Up @@ -317,8 +315,7 @@ impl Service for HydroflowCrateService {

async fn stop(&mut self) -> Result<()> {
ProgressTracker::with_group(
&self
.display_id
self.display_id
.clone()
.unwrap_or_else(|| format!("service/{}", self.id)),
None,
Expand All @@ -327,7 +324,7 @@ impl Service for HydroflowCrateService {
launched_binary.stdin().send("stop\n".to_string())?;

let timeout_result = ProgressTracker::leaf(
"waiting for exit".to_owned(),
"waiting for exit",
tokio::time::timeout(Duration::from_secs(60), launched_binary.wait()),
)
.await;
Expand Down
Loading
Loading