我试图让clokwerk安排一个异步函数每 X 秒运行一次。
文档显示了这个例子:
// Create a new scheduler
let mut scheduler = AsyncScheduler::new();
// Add some tasks to it
scheduler
.every(10.minutes())
.plus(30.seconds())
.run(|| async { println!("Simplest is just using an async block"); });
// Spawn a task to run it forever
tokio::spawn(async move {
loop {
scheduler.run_pending().await;
tokio::time::sleep(Duration::from_millis(100)).await;
}
});
Run Code Online (Sandbox Code Playgroud)
我的初步尝试:
let config2 = // define a Config struct, Config
let pg_pool2 = // get a sqlx connection pool, Pool<Postgres>
//I assume I need shared references …Run Code Online (Sandbox Code Playgroud)