Skip to content

Commit

Permalink
fix(cargo-shuttle): break deploy logs stream when...
Browse files Browse the repository at this point in the history
...StartResponse is received
  • Loading branch information
iulianbarbu committed Sep 7, 2023
1 parent b0e153b commit a0ad263
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use std::path::{Path, PathBuf};
use std::process::exit;
use std::str::FromStr;

use shuttle_common::deployment::{DEPLOYER_END_MESSAGES_BAD, DEPLOYER_END_MESSAGES_GOOD};
use shuttle_common::deployment::{
DEPLOYER_END_MESSAGES_BAD, DEPLOYER_END_MESSAGES_GOOD, DEPLOYER_START_RESPONSE,
};
use shuttle_common::models::deployment::CREATE_SERVICE_BODY_LIMIT;
use shuttle_common::{
claims::{ClaimService, InjectPropagation},
Expand Down Expand Up @@ -1157,13 +1159,19 @@ impl Shuttle {

return Ok(CommandOutcome::DeploymentFailure);
}

if DEPLOYER_END_MESSAGES_GOOD
.iter()
.any(|m| log_item.line.contains(m))
{
debug!("received end message, breaking deployment stream");
break;
}

if log_item.line.contains(DEPLOYER_START_RESPONSE) {
debug!("received start response inside the logs, breaking the loop");
break;
}
}
} else {
eprintln!("--- Reconnecting websockets logging ---");
Expand Down Expand Up @@ -1223,6 +1231,9 @@ impl Shuttle {
return Ok(CommandOutcome::DeploymentFailure);
}

// Print a newline in between the last deployment log line and the deployment details.
println!();

let service = client.get_service(self.ctx.project_name()).await?;
let resources = client
.get_service_resources(self.ctx.project_name())
Expand Down
1 change: 1 addition & 0 deletions common/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub const DEPLOYER_END_MSG_STARTUP_ERR: &str = "Service startup encountered an e
pub const DEPLOYER_END_MSG_CRASHED: &str = "Service encountered an error and crashed";
pub const DEPLOYER_END_MSG_STOPPED: &str = "Service was stopped by the user";
pub const DEPLOYER_END_MSG_COMPLETED: &str = "Service finished running all on its own";
pub const DEPLOYER_START_RESPONSE: &str = r#" [Deployer] {response="StartResponse { success: "#;

pub const DEPLOYER_END_MESSAGES_BAD: &[&str] =
&[DEPLOYER_END_MSG_STARTUP_ERR, DEPLOYER_END_MSG_CRASHED];
Expand Down

0 comments on commit a0ad263

Please sign in to comment.