Skip to content

Commit eac2a49

Browse files
authored
Merge pull request #46 from awslabs/dev
readiness check verify the http status code is successful (2xx)
2 parents 3440e44 + 14a96a9 commit eac2a49

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use lambda_extension::{service_fn as extension_handler, Extension};
55
use lambda_http::{service_fn as http_handler, Body, Request, Response};
66
use log::*;
77
use reqwest::{redirect, Client};
8-
use std::{env, mem};
9-
use tokio::runtime::Handle;
8+
use std::{env, future, mem};
109
use tokio_retry::{strategy::FixedInterval, Retry};
1110

1211
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
@@ -34,16 +33,13 @@ async fn main() -> Result<(), Error> {
3433
};
3534

3635
// register as an external extension
37-
let handle = Handle::current();
38-
tokio::task::spawn_blocking(move || {
39-
handle.spawn(async {
40-
Extension::new()
41-
.with_events(&[])
42-
.with_events_processor(extension_handler(|_| async { Ok::<(), Error>(()) }))
43-
.run()
44-
.await
45-
.expect("extension thread error");
46-
})
36+
tokio::task::spawn(async move {
37+
Extension::new()
38+
.with_events(&[])
39+
.with_events_processor(extension_handler(|_| async { Ok::<(), Error>(()) }))
40+
.run()
41+
.await
42+
.expect("extension thread error");
4743
});
4844

4945
// check if the application is ready every 10 milliseconds
@@ -52,9 +48,13 @@ async fn main() -> Result<(), Error> {
5248
"http://{}:{}{}",
5349
options.host, options.readiness_check_port, options.readiness_check_path
5450
);
55-
reqwest::get(readiness_check_url)
51+
match reqwest::blocking::get(readiness_check_url) {
52+
Ok(response) if { response.status().is_success() } => future::ready(Ok(())),
53+
_ => future::ready(Err::<(), i32>(-1)),
54+
}
5655
})
57-
.await?;
56+
.await
57+
.expect("application server is not ready");
5858

5959
// start lambda runtime
6060
let http_client = &Client::builder().redirect(redirect::Policy::none()).build().unwrap();

0 commit comments

Comments
 (0)