@@ -5,8 +5,7 @@ use lambda_extension::{service_fn as extension_handler, Extension};
5
5
use lambda_http:: { service_fn as http_handler, Body , Request , Response } ;
6
6
use log:: * ;
7
7
use reqwest:: { redirect, Client } ;
8
- use std:: { env, mem} ;
9
- use tokio:: runtime:: Handle ;
8
+ use std:: { env, future, mem} ;
10
9
use tokio_retry:: { strategy:: FixedInterval , Retry } ;
11
10
12
11
type Error = Box < dyn std:: error:: Error + Send + Sync + ' static > ;
@@ -34,16 +33,13 @@ async fn main() -> Result<(), Error> {
34
33
} ;
35
34
36
35
// 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" ) ;
47
43
} ) ;
48
44
49
45
// check if the application is ready every 10 milliseconds
@@ -52,9 +48,13 @@ async fn main() -> Result<(), Error> {
52
48
"http://{}:{}{}" ,
53
49
options. host, options. readiness_check_port, options. readiness_check_path
54
50
) ;
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
+ }
56
55
} )
57
- . await ?;
56
+ . await
57
+ . expect ( "application server is not ready" ) ;
58
58
59
59
// start lambda runtime
60
60
let http_client = & Client :: builder ( ) . redirect ( redirect:: Policy :: none ( ) ) . build ( ) . unwrap ( ) ;
0 commit comments