From 9957da9b182ca209ff8caa8f670d3bd7eff154bb Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Fri, 10 Nov 2023 12:23:31 +0100 Subject: add basic eta --- src/requests/start.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/requests/start.rs') diff --git a/src/requests/start.rs b/src/requests/start.rs index 882b154..ca4ca44 100644 --- a/src/requests/start.rs +++ b/src/requests/start.rs @@ -1,5 +1,5 @@ use futures_util::{StreamExt, SinkExt}; -use indicatif::MultiProgress; +use indicatif::{MultiProgress, ProgressBar}; use reqwest::StatusCode; use serde::Deserialize; use tokio_tungstenite::{connect_async, tungstenite::Message}; @@ -9,7 +9,7 @@ use crate::{error::CliError, default_headers, ErrorResponse, format_url, Protoco pub async fn start(id: String, ping: bool) -> Result<(), CliError> { let send_start = MultiProgress::new(); - let overview = add_pb(&send_start, OVERVIEW_STYLE, format!("start {}", id)); + let overview = add_pb(&send_start, OVERVIEW_STYLE, format!(") start {}", id)); // TODO: calculate average start-time on server let url = format_url("start", Protocols::Http)?; @@ -38,7 +38,7 @@ pub async fn start(id: String, ping: bool) -> Result<(), CliError> { } if ping { - let status = status_socket(body.uuid, &send_start).await?; + let status = status_socket(body.uuid, &send_start, &overview, id).await?; if status { finish_pb(overview, format!("successfully started {}", body.id), OVERVIEW_DONE); } else { @@ -59,7 +59,7 @@ pub async fn start(id: String, ping: bool) -> Result<(), CliError> { Ok(()) } -async fn status_socket(uuid: String, pb: &MultiProgress) -> Result { +async fn status_socket(uuid: String, pb: &MultiProgress, overview: &ProgressBar, id: String) -> Result { // TODO: Remove unwraps let ws_pb = add_pb(pb, DEFAULT_STYLE, "connect to websocket".to_string()); let (mut ws_stream, _response) = connect_async(format_url("status", Protocols::Websocket)?) @@ -68,6 +68,11 @@ async fn status_socket(uuid: String, pb: &MultiProgress) -> Result Result Result { + let spl: Vec<&str> = msg.split('_').collect(); + if (spl[0] != "eta") || (spl[2] != uuid) { return Err(CliError::WsResponse); }; + Ok(u64::from_str_radix(spl[1], 10).map_err(CliError::Parse)?) +} + fn verify_response(res: String, org_uuid: String) -> Result { let spl: Vec<&str> = res.split('_').collect(); let res_type = spl[0]; -- cgit v1.2.3