pub struct JobScheduler<'a> { /* private fields */ }
Expand description

The JobScheduler of rcron contains and executes the scheduled jobs.

Implementations

Create a new JobScheduler.

Add a job to the JobScheduler

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

Remove a job from the JobScheduler

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);

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.

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

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.