Struct job_scheduler_ng::JobScheduler
source · pub struct JobScheduler<'a> { /* private fields */ }
Expand description
The JobScheduler contains and executes the scheduled jobs.
Implementations§
source§impl<'a> JobScheduler<'a>
impl<'a> JobScheduler<'a>
sourcepub fn add(&mut self, job: Job<'a>) -> Uuid
pub fn add(&mut self, job: Job<'a>) -> Uuid
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!");
}));
sourcepub fn remove(&mut self, job_id: Uuid) -> bool
pub fn remove(&mut self, job_id: Uuid) -> bool
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);
sourcepub fn tick(&mut self)
pub fn tick(&mut self)
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));
}
sourcepub fn time_till_next_job(&self) -> Duration
pub fn time_till_next_job(&self) -> Duration
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§
source§impl<'a> Default for JobScheduler<'a>
impl<'a> Default for JobScheduler<'a>
source§fn default() -> JobScheduler<'a>
fn default() -> JobScheduler<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<'a> Freeze for JobScheduler<'a>
impl<'a> !RefUnwindSafe for JobScheduler<'a>
impl<'a> Send for JobScheduler<'a>
impl<'a> !Sync for JobScheduler<'a>
impl<'a> Unpin for JobScheduler<'a>
impl<'a> !UnwindSafe for JobScheduler<'a>
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