From 9ad0369c0da82c005fffcfc6b2fc93f6f50b339d Mon Sep 17 00:00:00 2001 From: Elias Posen Date: Thu, 22 Aug 2024 12:10:33 +0200 Subject: [PATCH] 10 min poll timeout --- core/src/cmds/docs.rs | 54 ++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/core/src/cmds/docs.rs b/core/src/cmds/docs.rs index a73697b..c7365f4 100644 --- a/core/src/cmds/docs.rs +++ b/core/src/cmds/docs.rs @@ -139,28 +139,40 @@ pub async fn handle_deploy_docs(name: &str, prod: bool, no_wait: bool) -> Result info!("Polling for completion, this may take a few minutes..."); // poll - let terminal_deployment = poll_deployment(&deployment).await?; - - if terminal_deployment.status.to_string() == DeploymentStatusEnum::Complete.to_string() { - if let Ok(doc_project) = client - .get_doc_project(GetDocProjectRequest { - project_id_or_name: name.to_string(), - }) - .await - { - let url = match &terminal_deployment.target { - DeploymentTargetEnum::Preview => doc_project.domains.preview.unwrap_or_default(), - DeploymentTargetEnum::Production => { - doc_project.domains.production.unwrap_or_default() + let poll_future = poll_deployment(&deployment); + match tokio::time::timeout(Duration::from_secs(600), poll_future).await { + Err(_timeout) => { + return Err(Error::general( + "Deployment did not complete within time out (10min)", + )); + } + Ok(poll_result) => { + let terminal_deployment = poll_result?; + if terminal_deployment.status.to_string() == DeploymentStatusEnum::Complete.to_string() + { + if let Ok(doc_project) = client + .get_doc_project(GetDocProjectRequest { + project_id_or_name: name.to_string(), + }) + .await + { + let url = match &terminal_deployment.target { + DeploymentTargetEnum::Preview => { + doc_project.domains.preview.unwrap_or_default() + } + DeploymentTargetEnum::Production => { + doc_project.domains.production.unwrap_or_default() + } + }; + + info!( + "{} deployment complete, available at https://{url}", + &terminal_deployment.target + ); + } else { + info!("{} deployment complete", &terminal_deployment.target) } - }; - - info!( - "{} deployment complete, available at https://{url}", - &terminal_deployment.target - ); - } else { - info!("{} deployment complete", &terminal_deployment.target) + } } }