Skip to content

Commit

Permalink
feat: [#433] add timeout to health_check binary
Browse files Browse the repository at this point in the history
```
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.
  • Loading branch information
josecelano committed Feb 9, 2024
1 parent 7c3f798 commit 4e7e920
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/bin/health_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
//!
//! - They are harder to maintain.
//! - They introduce new attack vectors.
use std::time::Duration;
use std::{env, process};

use reqwest::Client;

#[tokio::main]
async fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
eprintln!("Usage: cargo run --bin health_check <HEALTH_URL>");
eprintln!("Example: cargo run --bin health_check http://localhost:3002/health_check");
eprintln!("Example: cargo run --bin health_check http://127.0.0.1:3001/health_check");
std::process::exit(1);
}

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

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

match reqwest::get(url).await {
let client = Client::builder().timeout(Duration::from_secs(5)).build().unwrap();

match client.get(url).send().await {
Ok(response) => {
if response.status().is_success() {
println!("STATUS: {}", response.status());
Expand Down

0 comments on commit 4e7e920

Please sign in to comment.