diff options
author | Toby Vincent <tobyv@tobyvin.dev> | 2024-09-28 01:08:16 -0500 |
---|---|---|
committer | Toby Vincent <tobyv@tobyvin.dev> | 2024-09-28 01:08:16 -0500 |
commit | e1d9c956beb6921b0d549248bea3a6853fde5f46 (patch) | |
tree | c01098af5a024b00db50b0326dc67f79d7825ef9 /src/service/http.rs | |
parent | cd774827dd14f68d8405c45d2d9da30b3fab050e (diff) |
fix: clean up unused code and fix TCP client
Diffstat (limited to 'src/service/http.rs')
-rw-r--r-- | src/service/http.rs | 42 |
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")] |