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

fix: deployment state shown as running on startup crash #919

Merged
merged 2 commits into from
May 15, 2023
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
41 changes: 22 additions & 19 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,6 @@ impl Shuttle {
.get_logs_ws(self.ctx.project_name(), &deployment.id)
.await?;

let mut last_state: Option<shuttle_common::deployment::State> = None;

loop {
let message = stream.next().await;
if let Some(Ok(msg)) = message {
Expand All @@ -913,7 +911,6 @@ impl Shuttle {
| shuttle_common::deployment::State::Building
| shuttle_common::deployment::State::Built
| shuttle_common::deployment::State::Loading => {
last_state = Some(log_item.state.clone());
println!("{log_item}");
}
shuttle_common::deployment::State::Crashed => {
Expand All @@ -924,17 +921,13 @@ impl Shuttle {
println!();
print!("cargo shuttle logs {}", &deployment.id);
println!();
if last_state.is_none() {
println!("Note: Deploy failed immediately");
};

return Ok(CommandOutcome::DeploymentFailure);
}
shuttle_common::deployment::State::Running
| shuttle_common::deployment::State::Completed
| shuttle_common::deployment::State::Stopped
| shuttle_common::deployment::State::Unknown => {
last_state = Some(log_item.state);
break;
}
};
Expand All @@ -954,35 +947,45 @@ impl Shuttle {
// TODO: Make get_service_summary endpoint wait for a bit and see if it entered Running/Crashed state.
tokio::time::sleep(std::time::Duration::from_millis(500)).await;

let service = client.get_service(self.ctx.project_name()).await?;
let deployment = client
.get_deployment_details(self.ctx.project_name(), &deployment.id)
.await?;

// A deployment will only exist if there is currently one in the running state
if let Some(ref new_deployment) = service.deployment {
if deployment.state == shuttle_common::deployment::State::Running {
let service = client.get_service(self.ctx.project_name()).await?;

let resources = client
.get_service_resources(self.ctx.project_name())
.await?;
let resources = get_resources_table(&resources, self.ctx.project_name().as_str());

println!("{resources}{service}");

Ok(match new_deployment.state {
shuttle_common::deployment::State::Crashed => CommandOutcome::DeploymentFailure,
_ => CommandOutcome::Ok,
})
Ok(CommandOutcome::Ok)
} else {
println!("{}", "Deployment has not entered the running state".red());
println!();
match last_state {
Some(shuttle_common::deployment::State::Stopped) => {

match deployment.state {
shuttle_common::deployment::State::Stopped => {
println!("State: Stopped - Deployment was running, but has been stopped by the user.")
}
Some(shuttle_common::deployment::State::Completed) => {
shuttle_common::deployment::State::Completed => {
println!("State: Completed - Deployment was running, but stopped running all by itself.")
}
Some(shuttle_common::deployment::State::Unknown) => {
println!("State: Unknown - This may be because deployment was in an unknown state. We never expect this state and entering this state should be considered a bug.")
shuttle_common::deployment::State::Unknown => {
println!("State: Unknown - Deployment was in an unknown state. We never expect this state and entering this state should be considered a bug.")
}
shuttle_common::deployment::State::Crashed => {
println!(
"{}",
"State: Crashed - Deployment crashed after startup.".red()
);
}
_ => unreachable!(),
_ => println!(
"Deployment encountered an unexpected error - Please create a ticket to report this."
),
}

println!();
Expand Down
2 changes: 1 addition & 1 deletion common/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strum::Display;
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

#[derive(Clone, Debug, Deserialize, Display, Serialize)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Display, Serialize)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
Expand Down