use crate::executor::Executor;
use crate::ping_error::PingError;
use crate::task::http::http_ping::HttpPing;
use async_trait::async_trait;
use log::trace;
use std::time::Duration;
#[derive(Clone)]
pub struct HttpExecutor {
urn: String,
http_ping: HttpPing,
timeout: Duration,
}
impl HttpExecutor {
pub fn new(urn: String, timeout: Duration) -> Self {
let http_ping = HttpPing::new(urn.clone());
Self {
http_ping,
urn,
timeout,
}
}
}
#[async_trait]
impl Executor for HttpExecutor {
fn get_name(&self) -> String {
String::from("HTTP")
}
async fn exec(&self) -> Result<(), PingError> {
trace!("开始执行 HTTP 任务: ping {}", self.urn);
self.http_ping.ping(self.timeout).await
}
}