pub struct Cron { /* private fields */ }Implementations§
Source§impl Cron
impl Cron
pub fn list(&self) -> Vec<Job>
Sourcepub async fn add(&mut self, job: Job)
pub async fn add(&mut self, job: Job)
Examples found in repository?
examples/main.rs (line 16)
8async fn main() -> Result<()> {
9 // 构建一个Cron调度器实例,开启调试模式
10 let mut crond = CronBuilder::default().debug(true).build().unwrap();
11 // 启动Cron调度器
12 crond.run().await;
13
14 // 创建第1个任务,每秒触发一次,执行一个简单的打印操作
15 let j1 = Job::new("test", "* * * * * *", || println!("test"))?;
16 crond.add(j1).await;
17
18 // 创建第2个任务
19 sleep(Duration::from_secs(3)).await;
20 let j2 = Job::new("test2", "* * * * * *", || println!("test2"))?;
21 crond.add(j2.clone()).await;
22
23 // 移除第2个任务
24 sleep(Duration::from_secs(3)).await;
25 crond.remove(j2.id).await;
26
27 // 按下第1次Ctrl+C停止调度器
28 tokio::signal::ctrl_c().await?;
29 crond.stop();
30
31 // 按下第2次Ctrl+C信号退出进程
32 tokio::signal::ctrl_c().await?;
33 Ok(())
34}Sourcepub async fn remove(&mut self, id: JobId)
pub async fn remove(&mut self, id: JobId)
Examples found in repository?
examples/main.rs (line 25)
8async fn main() -> Result<()> {
9 // 构建一个Cron调度器实例,开启调试模式
10 let mut crond = CronBuilder::default().debug(true).build().unwrap();
11 // 启动Cron调度器
12 crond.run().await;
13
14 // 创建第1个任务,每秒触发一次,执行一个简单的打印操作
15 let j1 = Job::new("test", "* * * * * *", || println!("test"))?;
16 crond.add(j1).await;
17
18 // 创建第2个任务
19 sleep(Duration::from_secs(3)).await;
20 let j2 = Job::new("test2", "* * * * * *", || println!("test2"))?;
21 crond.add(j2.clone()).await;
22
23 // 移除第2个任务
24 sleep(Duration::from_secs(3)).await;
25 crond.remove(j2.id).await;
26
27 // 按下第1次Ctrl+C停止调度器
28 tokio::signal::ctrl_c().await?;
29 crond.stop();
30
31 // 按下第2次Ctrl+C信号退出进程
32 tokio::signal::ctrl_c().await?;
33 Ok(())
34}Sourcepub async fn run(&mut self)
pub async fn run(&mut self)
Examples found in repository?
examples/main.rs (line 12)
8async fn main() -> Result<()> {
9 // 构建一个Cron调度器实例,开启调试模式
10 let mut crond = CronBuilder::default().debug(true).build().unwrap();
11 // 启动Cron调度器
12 crond.run().await;
13
14 // 创建第1个任务,每秒触发一次,执行一个简单的打印操作
15 let j1 = Job::new("test", "* * * * * *", || println!("test"))?;
16 crond.add(j1).await;
17
18 // 创建第2个任务
19 sleep(Duration::from_secs(3)).await;
20 let j2 = Job::new("test2", "* * * * * *", || println!("test2"))?;
21 crond.add(j2.clone()).await;
22
23 // 移除第2个任务
24 sleep(Duration::from_secs(3)).await;
25 crond.remove(j2.id).await;
26
27 // 按下第1次Ctrl+C停止调度器
28 tokio::signal::ctrl_c().await?;
29 crond.stop();
30
31 // 按下第2次Ctrl+C信号退出进程
32 tokio::signal::ctrl_c().await?;
33 Ok(())
34}Sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Examples found in repository?
examples/main.rs (line 29)
8async fn main() -> Result<()> {
9 // 构建一个Cron调度器实例,开启调试模式
10 let mut crond = CronBuilder::default().debug(true).build().unwrap();
11 // 启动Cron调度器
12 crond.run().await;
13
14 // 创建第1个任务,每秒触发一次,执行一个简单的打印操作
15 let j1 = Job::new("test", "* * * * * *", || println!("test"))?;
16 crond.add(j1).await;
17
18 // 创建第2个任务
19 sleep(Duration::from_secs(3)).await;
20 let j2 = Job::new("test2", "* * * * * *", || println!("test2"))?;
21 crond.add(j2.clone()).await;
22
23 // 移除第2个任务
24 sleep(Duration::from_secs(3)).await;
25 crond.remove(j2.id).await;
26
27 // 按下第1次Ctrl+C停止调度器
28 tokio::signal::ctrl_c().await?;
29 crond.stop();
30
31 // 按下第2次Ctrl+C信号退出进程
32 tokio::signal::ctrl_c().await?;
33 Ok(())
34}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cron
impl RefUnwindSafe for Cron
impl Send for Cron
impl Sync for Cron
impl Unpin for Cron
impl UnwindSafe for Cron
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more