Skip to content

Commit

Permalink
fix: Timing of deployment status and local run printouts (#744)
Browse files Browse the repository at this point in the history
* Fix timing of local printout and deployment status

* fmt
  • Loading branch information
jonaro00 authored Apr 3, 2023
1 parent 515bd3f commit 07be36c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

58 changes: 28 additions & 30 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,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 @@ -291,16 +292,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 @@ -380,8 +376,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 @@ -431,8 +428,8 @@ impl Shuttle {

trace!("building project");
println!(
"{:>12} {}",
"Building".bold().green(),
"{} {}",
" Building".bold().green(),
working_directory.display()
);

Expand Down Expand Up @@ -533,7 +530,7 @@ impl Shuttle {
runtime::StorageManagerType::WorkingDir(working_directory.to_path_buf()),
&format!("http://localhost:{}", run_args.port + 1),
None,
portpicker::pick_unused_port().unwrap(),
portpicker::pick_unused_port().expect("unable to find available port"),
runtime_path,
)
.await
Expand Down Expand Up @@ -577,7 +574,7 @@ impl Shuttle {
.map(resource::Response::from_bytes)
.collect();

let resources = get_resources_table(&resources, service_name.as_str());
println!("{}", get_resources_table(&resources, service_name.as_str()));

let mut stream = runtime_client
.subscribe_logs(tonic::Request::new(SubscribeLogsRequest {}))
Expand All @@ -597,19 +594,23 @@ impl Shuttle {
}
});

println!("{resources}");

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

let addr = SocketAddr::new(
addr,
if run_args.external {
Ipv4Addr::new(0, 0, 0, 0)
} else {
Ipv4Addr::LOCALHOST
}
.into(),
portpicker::pick_unused_port().expect("unable to find available port"),
);

println!(
" {} {} on http://{}\n",
"Starting".bold().green(),
service_name,
addr
);

let start_request = StartRequest {
ip: addr.to_string(),
};
Expand All @@ -628,13 +629,6 @@ impl Shuttle {

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

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

runtime_handles.spawn(async move { runtime.wait().await });
}

Expand Down Expand Up @@ -695,6 +689,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

0 comments on commit 07be36c

Please sign in to comment.