Skip to content

Commit 4e7e920

Browse files
committed
feat: [#433] add timeout to health_check binary
``` cargo run --bin health_check http://127.0.0.1:3001/health_check ``` That command now fails if it does not get a response in 5 seconds.
1 parent 7c3f798 commit 4e7e920

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/bin/health_check.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44
//!
55
//! - They are harder to maintain.
66
//! - They introduce new attack vectors.
7+
use std::time::Duration;
78
use std::{env, process};
89

10+
use reqwest::Client;
11+
912
#[tokio::main]
1013
async fn main() {
1114
let args: Vec<String> = env::args().collect();
1215
if args.len() != 2 {
1316
eprintln!("Usage: cargo run --bin health_check <HEALTH_URL>");
14-
eprintln!("Example: cargo run --bin health_check http://localhost:3002/health_check");
17+
eprintln!("Example: cargo run --bin health_check http://127.0.0.1:3001/health_check");
1518
std::process::exit(1);
1619
}
1720

1821
println!("Health check ...");
1922

2023
let url = &args[1].clone();
2124

22-
match reqwest::get(url).await {
25+
let client = Client::builder().timeout(Duration::from_secs(5)).build().unwrap();
26+
27+
match client.get(url).send().await {
2328
Ok(response) => {
2429
if response.status().is_success() {
2530
println!("STATUS: {}", response.status());

0 commit comments

Comments
 (0)