nixfleet_agent/runtime/workers/probe_runners/
http.rs1use chrono::{DateTime, Utc};
10
11use super::{ProbeDecl, RunnerOutcome};
12
13pub async fn run(decl: &ProbeDecl, now: DateTime<Utc>) -> RunnerOutcome {
14 let Some(url) = decl.url.as_deref() else {
15 return RunnerOutcome::fail(now, "http probe: url missing");
16 };
17 let client = match reqwest::Client::builder()
18 .timeout(std::time::Duration::from_secs(decl.timeout_secs))
19 .build()
20 {
21 Ok(c) => c,
22 Err(err) => return RunnerOutcome::fail(now, format!("http probe: client build: {err}")),
23 };
24 match client.get(url).send().await {
25 Ok(resp) => {
26 let got = resp.status().as_u16();
27 if got == decl.expect_status {
28 RunnerOutcome::pass(now)
29 } else {
30 RunnerOutcome::fail(
31 now,
32 format!(
33 "http probe: status {got} != expected {}",
34 decl.expect_status
35 ),
36 )
37 }
38 }
39 Err(err) => RunnerOutcome::fail(now, format!("http probe: send: {err}")),
40 }
41}