summaryrefslogtreecommitdiffstats
path: root/src/service/http.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/http.rs')
-rw-r--r--src/service/http.rs42
1 files changed, 0 insertions, 42 deletions
diff --git a/src/service/http.rs b/src/service/http.rs
index 6d21cb7..7c875b9 100644
--- a/src/service/http.rs
+++ b/src/service/http.rs
@@ -1,10 +1,8 @@
use std::{fmt::Display, time::Duration};
use axum::http::status::StatusCode;
-use futures::Stream;
use serde::Deserialize;
use tokio::sync::watch::Sender;
-use tokio_stream::wrappers::WatchStream;
use url::Url;
use crate::{Error, Status};
@@ -22,12 +20,6 @@ pub struct Http {
pub client: Option<reqwest::Client>,
}
-impl Display for Http {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{} {}", self.method, self.url)
- }
-}
-
impl ServiceSpawner for Http {
async fn spawn(self, tx: Sender<Status>) -> Result<(), Error> {
let client = self.client.unwrap_or_default();
@@ -54,40 +46,6 @@ impl ServiceSpawner for Http {
}
}
-impl Http {
- pub fn into_stream(self, client: reqwest::Client) -> impl Stream<Item = Status> {
- let request = client
- .request(self.method.into(), self.url)
- .build()
- .expect("Url parsing should not fail");
-
- let (tx, rx) = tokio::sync::watch::channel(Status::default());
-
- tokio::spawn(async move {
- let mut interval = tokio::time::interval(Duration::from_secs(5));
- loop {
- interval.tick().await;
- let req = request
- .try_clone()
- .expect("Clone with no body should never fail");
- let resp = client.execute(req).await;
- let status = match resp.map(|r| r.status().as_u16()) {
- Ok(code) if code == self.status_code => Status::Pass,
- Ok(code) => Status::Fail(Some(format!("Status code: {code}"))),
- Err(err) => {
- tracing::error!("HTTP request error: {err}");
- Status::Unknown
- }
- };
-
- tx.send_if_modified(|s| s.update(status));
- }
- });
-
- WatchStream::new(rx)
- }
-}
-
#[derive(Debug, Clone, Copy, Default, Deserialize)]
pub enum Method {
#[serde(alias = "get", alias = "GET")]