scheduled-task

Crates.ioscheduled-task
lib.rsscheduled-task
version0.1.3
created_at2025-10-22 03:53:31.750722+00
updated_at2025-10-27 00:58:39.443671+00
description对tokio-cron-scheduler库的增强
homepage
repositoryhttps://gitee.com/itao007/scheduled-task.git
max_upload_size
id1894907
size20,314
itao (bj-sjt)

documentation

https://docs.rs/scheduled-task

README

通过#[scheduled]属性宏生成定时任务 #[scheduled]有两个属性

  • cron:指定表达式, 如:cron = "*/1 * * * * *"
  • rate:指定时间频率,单位:秒, 如:rate = 2

注意: cron和rate两者必须且只能有一个有值

#[scheduled]必须添加在一个无参数、无返回值的异步函数上, 然后需要执行一下该函数,定时任务才能生效

Example

#[scheduled(cron = "*/1 * * * * *")]
async fn func1() {
    println!("func1");
}
#[tokio::main]
async fn main() {
    run_cron_task!(func1);
    // 或
    // func1().await;
}
Commit count: 0

cargo fmt