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

chore: simplify debug logging for app readiness checks #520

Merged
merged 7 commits into from
Jan 3, 2025
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ use std::{
},
time::Duration,
};
use tokio::net::TcpStream;
use tokio::time::timeout;
use tokio::{
net::TcpStream,
time::{timeout, Instant},
};
use tokio_retry::{strategy::FixedInterval, Retry};
use tower::{Service, ServiceBuilder};
use tower_http::compression::CompressionLayer;
Expand Down Expand Up @@ -231,7 +233,14 @@ impl Adapter<HttpConnector, Body> {
}

async fn is_web_ready(&self, url: &Url, protocol: &Protocol) -> bool {
let start = Instant::now();
let interval = 5; // TODO: make this configurable?
DiscreteTom marked this conversation as resolved.
Show resolved Hide resolved
let mut next_checkpoint = interval;
Retry::spawn(FixedInterval::from_millis(10), || {
if start.elapsed().as_secs() > next_checkpoint {
tracing::debug!("app is not ready after {next_checkpoint}s");
DiscreteTom marked this conversation as resolved.
Show resolved Hide resolved
next_checkpoint += interval;
}
self.check_web_readiness(url, protocol)
})
.await
Expand All @@ -247,10 +256,11 @@ impl Adapter<HttpConnector, Body> {
&& response.status().as_u16() >= 100
} =>
{
tracing::debug!("app is ready");
Ok(())
}
_ => {
tracing::debug!("app is not ready");
tracing::trace!("app is not ready");
Err(-1)
}
},
Expand Down