Skip to content

Commit

Permalink
polling spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasposen committed Aug 22, 2024
1 parent 04e8335 commit 13eee81
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 19 deletions.
89 changes: 70 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ semver = "1.0.23"
heck = "0.5.0"
clap-markdown = "0.1.4"
sideko_rest_api = "0.1.1"
spinners = "4.1.1"
8 changes: 8 additions & 0 deletions core/src/cmds/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use sideko_rest_api::{
},
Client as SidekoClient,
};
use spinners::{Spinner, Spinners};

pub async fn handle_list_docs() -> Result<()> {
// check for updates after all other validation passed
Expand Down Expand Up @@ -173,6 +174,8 @@ async fn poll_deployment(deployment: &Deployment) -> Result<Deployment> {
.with_api_key_auth(&api_key);
let mut current_status: DeploymentStatusEnum = deployment.status.clone();

let mut sp = Spinner::new(Spinners::Dots, "Polling deployment...".into());

loop {
tokio::time::sleep(Duration::from_secs(2)).await;

Expand All @@ -194,14 +197,18 @@ async fn poll_deployment(deployment: &Deployment) -> Result<Deployment> {

let status_str = d.status.to_string();
if current_status.to_string() != status_str {
sp.stop_with_newline();
debug!("Deployment status updated to {}", &d.status);
sp = Spinner::new(Spinners::Dots, "Polling deployment...".into());
current_status = d.status.clone();
}

if status_str == DeploymentStatusEnum::Cancelled.to_string() {
sp.stop_with_newline();
warn!("Deployment has been cancelled");
return Ok(d);
} else if status_str == DeploymentStatusEnum::Error.to_string() {
sp.stop_with_newline();
return Err(Error::general_with_debug(
"Deployment failed",
&format!(
Expand All @@ -211,6 +218,7 @@ async fn poll_deployment(deployment: &Deployment) -> Result<Deployment> {
),
));
} else if status_str == DeploymentStatusEnum::Complete.to_string() {
sp.stop_with_newline();
return Ok(d);
}
}
Expand Down

0 comments on commit 13eee81

Please sign in to comment.