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: Timing of deployment status and local run printouts #744

Merged
merged 6 commits into from
Apr 3, 2023
Merged
Changes from 4 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
66 changes: 31 additions & 35 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ impl Shuttle {
}

async fn stop(&self, client: &Client) -> Result<()> {
let mut service = client.stop_service(self.ctx.project_name()).await?;
let proj_name = self.ctx.project_name();
let mut service = client.stop_service(proj_name).await?;

let progress_bar = create_spinner();
loop {
Expand All @@ -303,16 +304,11 @@ impl Shuttle {
}

progress_bar.set_message(format!("Stopping {}", deployment.id));
service = client.get_service(self.ctx.project_name()).await?;
service = client.get_service(proj_name).await?;
}
progress_bar.finish_and_clear();

println!(
r#"{}
{}"#,
"Successfully stopped service".bold(),
service
);
println!("{}\n{}", "Successfully stopped service".bold(), service);

Ok(())
}
Expand Down Expand Up @@ -392,8 +388,9 @@ impl Shuttle {
}

async fn deployments_list(&self, client: &Client) -> Result<()> {
let deployments = client.get_deployments(self.ctx.project_name()).await?;
let table = get_deployments_table(&deployments, self.ctx.project_name().as_str());
let proj_name = self.ctx.project_name();
let deployments = client.get_deployments(proj_name).await?;
let table = get_deployments_table(&deployments, proj_name.as_str());

println!("{table}");

Expand Down Expand Up @@ -439,12 +436,13 @@ impl Shuttle {
}
});

let service_name = self.ctx.project_name();
let working_directory = self.ctx.working_directory();

trace!("building project");
println!(
"{:>12} {}",
"Building".bold().green(),
"{} {}",
" Building".bold().green(),
jonaro00 marked this conversation as resolved.
Show resolved Hide resolved
working_directory.display()
);

Expand All @@ -471,8 +469,6 @@ impl Shuttle {
Default::default()
};

let service_name = self.ctx.project_name().to_string();

let (is_wasm, executable_path) = match runtime {
Runtime::Next(path) => (true, path),
Runtime::Alpha(path) => (false, path),
Expand Down Expand Up @@ -547,7 +543,6 @@ impl Shuttle {
.await
.map_err(|err| {
provisioner_server.abort();

err
})?;

Expand All @@ -556,7 +551,7 @@ impl Shuttle {
.into_os_string()
.into_string()
.expect("to convert path to string"),
service_name: service_name.clone(),
service_name: service_name.to_string(),
resources: Default::default(),
secrets,
});
Expand All @@ -577,14 +572,6 @@ impl Shuttle {
exit(1);
}

let resources = response
.resources
.into_iter()
.map(resource::Response::from_bytes)
.collect();

let resources = get_resources_table(&resources, self.ctx.project_name().as_str());

let mut stream = runtime_client
.subscribe_logs(tonic::Request::new(SubscribeLogsRequest {}))
.or_else(|err| async {
Expand All @@ -603,15 +590,27 @@ impl Shuttle {
}
});

println!("{resources}");
let resources = response
.resources
.into_iter()
.map(resource::Response::from_bytes)
.collect();

println!("{}", get_resources_table(&resources));

let addr = if run_args.external {
std::net::IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))
Ipv4Addr::new(0, 0, 0, 0)
} else {
Ipv4Addr::LOCALHOST.into()
Ipv4Addr::LOCALHOST
};
let addr = SocketAddr::new(addr.into(), run_args.port);

let addr = SocketAddr::new(addr, run_args.port);
println!(
" {} {} on http://{}\n",
"Starting".bold().green(),
service_name,
addr
);
jonaro00 marked this conversation as resolved.
Show resolved Hide resolved

let start_request = StartRequest {
ip: addr.to_string(),
Expand All @@ -631,13 +630,6 @@ impl Shuttle {

trace!(response = ?response, "client response: ");

println!(
"\n{:>12} {} on http://{}",
"Starting".bold().green(),
self.ctx.project_name(),
addr
);

runtime.wait().await?;

Ok(())
Expand Down Expand Up @@ -688,6 +680,10 @@ impl Shuttle {
}
}

// Temporary fix.
// 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?;

// A deployment will only exist if there is currently one in the running state
Expand Down