Rust Actix Web:每10秒运行一次服务

Rust Actix Web:每10秒运行一次服务,rust,actix-web,Rust,Actix Web,我目前正在使用Rust和Actix Web实现一个服务器。我现在的任务是每10秒从这个服务器向另一个服务器发送一个请求(ping请求)。ping请求本身在异步函数中实现: async fn ping(client: web::Data<Client>, state: Data<AppState>) -> Result<HttpResponse, Error> {} async-fn-ping(客户端:web::Data,状态:Data)->结果{}

我目前正在使用Rust和Actix Web实现一个服务器。我现在的任务是每10秒从这个服务器向另一个服务器发送一个请求(ping请求)。ping请求本身在
异步
函数中实现:

async fn ping(client: web::Data<Client>, state: Data<AppState>) -> Result<HttpResponse, Error> {}
async-fn-ping(客户端:web::Data,状态:Data)->结果{}
这是我的简单服务器的主要功能:

async fn ping(client: web::Data<Client>, state: Data<AppState>) -> Result<HttpResponse, Error> {}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    ::std::env::set_var("RUST_LOG", "debug");
    env_logger::init();
    let args = config::CliOptions::from_args();
    let config =
        config::Config::new(args.config_file.as_path()).expect("Failed to config");
    let address = config.address.clone();
    let app_state = AppState::new(config).unwrap();

    println!("Started http server: http://{}", address);

    HttpServer::new(move || {
        App::new()
            .data(app_state.clone())
            .app_data(app_state.clone())
            .data(Client::default())
            .default_service(web::resource("/").route(web::get().to(index)))
    })
    .bind(address)?
    .run()
    .await
}
#[actix\u rt::main]
异步fn main()->std::io::Result{
:std::env::set_var(“RUST_LOG”、“debug”);
环境记录器::init();
让args=config::CliOptions::from_args();
让配置=
config::config::new(args.config_file.as_path()).expect(“配置失败”);
让address=config.address.clone();
让app_state=AppState::new(config).unwrap();
println!(“启动的http服务器:http://{}”,地址);
HttpServer::新建(移动| |{
App::new()
.data(app_state.clone())
.app\u数据(app\u state.clone())
.data(客户端::默认值())
.default_服务(web::resource(“/”).route(web::get().to(index)))
})
.绑定(地址)?
.run()
.等待
}
我尝试使用东京,但这太复杂了,因为所有不同的异步函数和它们的生命周期都不同

那么,在actix web中是否有任何简单的方法可以在服务器启动后每10秒执行一次ping功能(可能作为一项服务)

谢谢

请参阅和

以下是一个例子:

spawn(异步移动){
让mut interval=time::interval(持续时间::from_secs(10));
环路{
interval.tick()等待;
//做点什么
}
});
这是可行的,但唯一的一点是它不会向调用者重新发送http响应

用于启动一个任务,该任务在循环中使用等待10秒并执行ping?还有一个“生成一个作业,以指定的固定间隔周期性地执行给定的闭包”