Struct tokio_cron_scheduler::JobScheduler[][src]

pub struct JobScheduler(_);

The JobScheduler contains and executes the scheduled jobs.

Implementations

impl JobsSchedulerLocked[src]

pub fn new() -> JobsSchedulerLocked[src]

Create a new JobSchedulerLocked.

pub fn add(&mut self, job: JobLocked) -> Result<(), Box<dyn Error>>[src]

Add a job to the JobScheduler

use tokio_cron_scheduler::{Job, JobScheduler, JobToRun};
let mut sched = JobScheduler::new();
sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
    println!("I get executed every 10 seconds!");
}));

pub fn remove(&mut self, to_be_removed: &Uuid) -> Result<(), Box<dyn Error>>[src]

Remove a job from the JobScheduler

use tokio_cron_scheduler::{Job, JobScheduler, JobToRun};
let mut sched = JobScheduler::new();
let job_id = sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
    println!("I get executed every 10 seconds!");
}));
sched.remove(job_id);

pub fn tick(&mut self) -> Result<(), Box<dyn Error>>[src]

The tick method increments time for the JobScheduler and executes any pending jobs. It is recommended to sleep for at least 500 milliseconds between invocations of this method. This is kept public if you’re running this yourself. It is better to call the start method if you want all of this automated for you.

loop {
    sched.tick();
    std::thread::sleep(Duration::from_millis(500));
}

pub fn start(&self) -> JoinHandle<()>[src]

The start spawns a Tokio task where it loops. Every 500ms it runs the tick method to increment any any pending jobs.

if let Err(e) = sched.start().await {
        eprintln!("Error on scheduler {:?}", e);
    }

pub fn time_till_next_job(&self) -> Result<Duration, Box<dyn Error>>[src]

The time_till_next_job method returns the duration till the next job is supposed to run. This can be used to sleep until then without waking up at a fixed interval.AsMut

loop {
    sched.tick();
    std::thread::sleep(sched.time_till_next_job());
}

Trait Implementations

impl Clone for JobsSchedulerLocked[src]

impl Default for JobsSchedulerLocked[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.