client: Retry failing send()s
This commit is contained in:
parent
02110d9826
commit
cf7f54adb5
1 changed files with 8 additions and 6 deletions
|
@ -4,13 +4,15 @@ use spaceapi::Status;
|
|||
fn get_spaceapi(url: String) -> Status {
|
||||
let user_agent = "spaceapi2prometheus";
|
||||
let status: Status;
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.user_agent(user_agent)
|
||||
.build()
|
||||
.unwrap()
|
||||
.get(url);
|
||||
loop {
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.user_agent(user_agent)
|
||||
.build();
|
||||
if let Ok(c) = client {
|
||||
let res = c.get(url).send().unwrap().text().unwrap();
|
||||
status = serde_json::from_str(&res).unwrap();
|
||||
let res = client.try_clone().unwrap().send();
|
||||
if let Ok(r) = res {
|
||||
status = serde_json::from_str(&r.text().unwrap()).unwrap();
|
||||
break;
|
||||
}
|
||||
eprintln!("Failed to connect to endpoint, trying again!");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue