Cron

Struct Cron 

Source
pub struct Cron { /* private fields */ }

Implementations§

Source§

impl Cron

Source

pub fn list(&self) -> Vec<Job>

Source

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}
Source

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}
Source

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}
Source

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§

Source§

impl Default for Cron

Source§

fn default() -> Cron

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V