|
1 | 1 | use std::net::SocketAddr;
|
2 | 2 | use std::sync::Arc;
|
3 |
| -use std::time::Duration; |
4 | 3 |
|
5 |
| -use colored::Colorize; |
6 |
| -use reqwest::{Client as HttpClient, Url}; |
| 4 | +use reqwest::Url; |
7 | 5 |
|
8 | 6 | use super::checks;
|
9 | 7 | use super::config::Configuration;
|
@@ -37,52 +35,8 @@ impl Service {
|
37 | 35 |
|
38 | 36 | checks::http::run(&self.config.http_trackers, &self.console, &mut check_results).await;
|
39 | 37 |
|
40 |
| - self.run_health_checks(&mut check_results).await; |
| 38 | + checks::health::run(&self.config.health_checks, &self.console, &mut check_results).await; |
41 | 39 |
|
42 | 40 | check_results
|
43 | 41 | }
|
44 |
| - |
45 |
| - async fn run_health_checks(&self, check_results: &mut Vec<CheckResult>) { |
46 |
| - self.console.println("Health checks ..."); |
47 |
| - |
48 |
| - for health_check_url in &self.config.health_checks { |
49 |
| - match self.run_health_check(health_check_url.clone()).await { |
50 |
| - Ok(()) => check_results.push(Ok(())), |
51 |
| - Err(err) => check_results.push(Err(err)), |
52 |
| - } |
53 |
| - } |
54 |
| - } |
55 |
| - |
56 |
| - async fn run_health_check(&self, url: Url) -> Result<(), CheckError> { |
57 |
| - let client = HttpClient::builder().timeout(Duration::from_secs(5)).build().unwrap(); |
58 |
| - |
59 |
| - let colored_url = url.to_string().yellow(); |
60 |
| - |
61 |
| - match client.get(url.clone()).send().await { |
62 |
| - Ok(response) => { |
63 |
| - if response.status().is_success() { |
64 |
| - self.console |
65 |
| - .println(&format!("{} - Health API at {} is OK", "✓".green(), colored_url)); |
66 |
| - Ok(()) |
67 |
| - } else { |
68 |
| - self.console.eprintln(&format!( |
69 |
| - "{} - Health API at {} is failing: {:?}", |
70 |
| - "✗".red(), |
71 |
| - colored_url, |
72 |
| - response |
73 |
| - )); |
74 |
| - Err(CheckError::HealthCheckError { url }) |
75 |
| - } |
76 |
| - } |
77 |
| - Err(err) => { |
78 |
| - self.console.eprintln(&format!( |
79 |
| - "{} - Health API at {} is failing: {:?}", |
80 |
| - "✗".red(), |
81 |
| - colored_url, |
82 |
| - err |
83 |
| - )); |
84 |
| - Err(CheckError::HealthCheckError { url }) |
85 |
| - } |
86 |
| - } |
87 |
| - } |
88 | 42 | }
|
0 commit comments