Struct rcron::JobScheduler
source · pub struct JobScheduler<'a> { /* private fields */ }
Expand description
The JobScheduler of rcron contains and executes the scheduled jobs.
Implementations§
source§impl<'a> JobScheduler<'a>
impl<'a> JobScheduler<'a>
sourcepub fn new() -> JobScheduler<'a>
pub fn new() -> JobScheduler<'a>
Create a new JobScheduler
.
Examples found in repository?
examples/rcron_basic.rs (line 5)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
let mut sched = JobScheduler::new();
sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
println!("exec task every 10 seconds!");
}));
sched.add(Job::new("1/5 * * * * *".parse().unwrap(), || {
println!("exec task every 5 seconds!");
}));
loop {
sched.tick();
std::thread::sleep(Duration::from_millis(500));
}
}
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!");
}));
Examples found in repository?
examples/rcron_basic.rs (lines 7-9)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
let mut sched = JobScheduler::new();
sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
println!("exec task every 10 seconds!");
}));
sched.add(Job::new("1/5 * * * * *".parse().unwrap(), || {
println!("exec task every 5 seconds!");
}));
loop {
sched.tick();
std::thread::sleep(Duration::from_millis(500));
}
}
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));
}
Examples found in repository?
examples/rcron_basic.rs (line 16)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
let mut sched = JobScheduler::new();
sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
println!("exec task every 10 seconds!");
}));
sched.add(Job::new("1/5 * * * * *".parse().unwrap(), || {
println!("exec task every 5 seconds!");
}));
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> !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