Skip to content

Commit 8315daa

Browse files
committed
monitor endpoint return not 200 when data not fresh
1 parent 480cf28 commit 8315daa

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/server/route.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,33 +136,36 @@ pub async fn route(
136136
// it consider 10 times the expected interval between blocks to be "strange"
137137

138138
let ts = state.tip_timestamp().await;
139-
let s = match ts {
139+
let (code, s) = match ts {
140140
Some(ts) => {
141141
let now = SystemTime::now()
142142
.duration_since(UNIX_EPOCH)
143143
.map_err(|e| Error::String(e.to_string()))?;
144144
let delta = now.as_secs().saturating_sub(ts as u64);
145-
let more_or_less = match network.into() {
145+
let (code, more_or_less) = match network.into() {
146146
Family::Elements => {
147147
if delta > 600 {
148-
"more than 10 minutes"
148+
(StatusCode::SERVICE_UNAVAILABLE, "more than 10 minutes")
149149
} else {
150-
"less than 10 minutes"
150+
(StatusCode::OK, "less than 10 minutes")
151151
}
152152
}
153153
Family::Bitcoin => {
154154
if delta > 6000 {
155-
"more than 100 minutes"
155+
(StatusCode::SERVICE_UNAVAILABLE, "more than 100 minutes")
156156
} else {
157-
"less than 100 minutes"
157+
(StatusCode::OK, "less than 100 minutes")
158158
}
159159
}
160160
};
161-
format!("{delta} seconds since last block, {more_or_less}")
161+
(
162+
code,
163+
format!("{delta} seconds since last block, {more_or_less}"),
164+
)
162165
}
163-
None => "unknown".to_string(),
166+
None => (StatusCode::SERVICE_UNAVAILABLE, "unknown".to_string()),
164167
};
165-
str_resp(s, StatusCode::OK)
168+
str_resp(s, code)
166169
}
167170
(&Method::GET, "/v1/build_info", None) => {
168171
let build_info = get_build_info();

0 commit comments

Comments
 (0)