pong_rs/task/http/
http_executor.rs1use crate::executor::Executor;
2use crate::ping_error::PingError;
3use crate::task::http::http_ping::HttpPing;
4use async_trait::async_trait;
5use log::trace;
6use std::time::Duration;
7
8#[derive(Clone)]
9pub struct HttpExecutor {
10 urn: String,
11 http_ping: HttpPing,
12 timeout: Duration,
13}
14
15impl HttpExecutor {
16 pub fn new(urn: String, timeout: Duration) -> Self {
21 let http_ping = HttpPing::new(urn.clone());
22
23 Self {
24 http_ping,
25 urn,
26 timeout,
27 }
28 }
29}
30
31#[async_trait]
32impl Executor for HttpExecutor {
33 fn get_name(&self) -> String {
34 String::from("HTTP")
35 }
36
37 async fn exec(&self) -> Result<(), PingError> {
38 trace!("开始执行 HTTP 任务: ping {}", self.urn);
39 self.http_ping.ping(self.timeout).await
40 }
41}