1
1
use {
2
- crate :: { api:: ApiState , state:: aggregate:: Aggregates } ,
2
+ crate :: { api:: ApiState , state:: { aggregate:: Aggregates , cache :: Cache } } ,
3
3
axum:: {
4
4
extract:: State ,
5
5
http:: StatusCode ,
6
6
response:: { IntoResponse , Response } ,
7
7
Json ,
8
8
} ,
9
+ serde_json:: json,
9
10
} ;
10
11
11
12
/// Endpoint that returns OK (200) only when the cache is fully hydrated.
@@ -19,11 +20,20 @@ use {
19
20
/// along with detailed metadata about the readiness state.
20
21
pub async fn ready < S > ( State ( state) : State < ApiState < S > > ) -> Response
21
22
where
22
- S : Aggregates ,
23
+ S : Aggregates + Cache ,
23
24
{
24
25
let state = & * state. state ;
25
- match Aggregates :: is_ready ( state) . await {
26
- ( true , _) => ( StatusCode :: OK , "OK" ) . into_response ( ) ,
27
- ( false , metadata) => ( StatusCode :: SERVICE_UNAVAILABLE , Json ( metadata) ) . into_response ( ) ,
26
+ let ( aggregates_ready, metadata) = Aggregates :: is_ready ( state) . await ;
27
+ let cache_ready = Cache :: is_ready ( state) . await ;
28
+
29
+ if aggregates_ready && cache_ready {
30
+ ( StatusCode :: OK , "OK" ) . into_response ( )
31
+ } else {
32
+ let response_metadata = json ! ( {
33
+ "aggregates_ready" : aggregates_ready,
34
+ "cache_ready" : cache_ready,
35
+ "details" : metadata
36
+ } ) ;
37
+ ( StatusCode :: SERVICE_UNAVAILABLE , Json ( response_metadata) ) . into_response ( )
28
38
}
29
39
}
0 commit comments