-
Notifications
You must be signed in to change notification settings - Fork 127
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 readiness check function #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
use lambda_extension::Extension; | ||
use lambda_http::{Body, Request, RequestExt, Response}; | ||
use reqwest::{redirect, Client, Url}; | ||
use std::{env, future::Future, mem, pin::Pin, time::Duration}; | ||
use std::{env, future, future::Future, mem, pin::Pin, time::Duration}; | ||
use tokio::{runtime::Handle, time::timeout}; | ||
use tokio_retry::{strategy::FixedInterval, Retry}; | ||
use tower::Service; | ||
|
@@ -95,20 +95,13 @@ impl Adapter { | |
|
||
async fn check_readiness(&self) -> bool { | ||
Retry::spawn(FixedInterval::from_millis(10), || { | ||
let fut = self.check_health_url(); | ||
async move { fut.await } | ||
match reqwest::blocking::get(&self.healthcheck_url) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see the benefit of using |
||
Ok(response) if { response.status().is_success() } => future::ready(Ok(())), | ||
_ => future::ready(Err::<(), i32>(-1)), | ||
} | ||
}) | ||
.await | ||
.unwrap() | ||
} | ||
|
||
async fn check_health_url(&self) -> Result<bool, std::convert::Infallible> { | ||
self.client | ||
.head(&self.healthcheck_url) | ||
.send() | ||
.await | ||
.map(|r| r.status().is_success()) | ||
.or(Ok(false)) | ||
.is_ok() | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function doesn't need to be
async
if the request blocks the thread.