use 5s timeout for get request

This commit is contained in:
Joachim Lusiardi 2024-02-08 15:13:05 +01:00
parent 60434be505
commit 0aca77375f
1 changed files with 8 additions and 1 deletions

View File

@ -45,6 +45,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut write_queries: Vec<WriteQuery> = Vec::new(); let mut write_queries: Vec<WriteQuery> = Vec::new();
let http_client = reqwest::Client::builder()
.timeout(core::time::Duration::from_secs(5))
.build()
.unwrap();
if let Some(configs) = config_data["configs"].as_array() { if let Some(configs) = config_data["configs"].as_array() {
for config in configs { for config in configs {
let mut handlebars = Handlebars::new(); let mut handlebars = Handlebars::new();
@ -54,7 +59,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = handlebars.render("url", &data).unwrap(); let url = handlebars.render("url", &data).unwrap();
println!("URL: {}", url); println!("URL: {}", url);
let response_json: serde_json::Value = reqwest::get(url) let response_json: serde_json::Value = http_client
.get(url)
.send()
.await? .await?
.json() .json()
.await?; .await?;