From e1d9c956beb6921b0d549248bea3a6853fde5f46 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sat, 28 Sep 2024 01:08:16 -0500 Subject: fix: clean up unused code and fix TCP client --- src/service/http.rs | 42 ------------------------------------------ 1 file changed, 42 deletions(-) (limited to 'src/service/http.rs') 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, } -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) -> 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 { - 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")] -- cgit v1.2.3-70-g09d2