pub struct Cron<Z>{ /* private fields */ }Implementations§
source§impl<Z> Cron<Z>
impl<Z> Cron<Z>
Cron contains and executes the scheduled jobs.
sourcepub fn new(tz: Z) -> Cron<Z>
pub fn new(tz: Z) -> Cron<Z>
Create a new cron.
ⓘ
let mut cron = cron::Cron::new(Utc);
cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start(); Examples found in repository?
examples/simple.rs (line 6)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let local_tz = Local::from_offset(&FixedOffset::east(7));
let mut cron = cron_tab::Cron::new(local_tz);
let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();
// start cron in background
cron.start();
cron.add_fn("* * * * * *", move || {
println!("add_fn {}", Local::now().to_string());
})
.unwrap();
// remove job_test
cron.remove(first_job_id);
std::thread::sleep(std::time::Duration::from_secs(10));
// stop cron
cron.stop();
}sourcepub fn add_fn<T>(&mut self, spec: &str, f: T) -> Result<usize>
pub fn add_fn<T>(&mut self, spec: &str, f: T) -> Result<usize>
Add a function to Cron.
ⓘ
let mut cron = cron::Cron::new(Utc);
cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start(); Examples found in repository?
examples/simple.rs (line 8)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let local_tz = Local::from_offset(&FixedOffset::east(7));
let mut cron = cron_tab::Cron::new(local_tz);
let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();
// start cron in background
cron.start();
cron.add_fn("* * * * * *", move || {
println!("add_fn {}", Local::now().to_string());
})
.unwrap();
// remove job_test
cron.remove(first_job_id);
std::thread::sleep(std::time::Duration::from_secs(10));
// stop cron
cron.stop();
}sourcepub fn set_timezone(&mut self, tz: Z)
pub fn set_timezone(&mut self, tz: Z)
Set timezone offset.
ⓘ
let mut cron = cron::Cron::new(Utc);
cron.start(); sourcepub fn remove(&self, id: usize)
pub fn remove(&self, id: usize)
Remove a job from Cron.
ⓘ
let mut cron = cron::Cron::new();
let job_id = cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start();
cron.remove(job_id); Examples found in repository?
examples/simple.rs (line 19)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let local_tz = Local::from_offset(&FixedOffset::east(7));
let mut cron = cron_tab::Cron::new(local_tz);
let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();
// start cron in background
cron.start();
cron.add_fn("* * * * * *", move || {
println!("add_fn {}", Local::now().to_string());
})
.unwrap();
// remove job_test
cron.remove(first_job_id);
std::thread::sleep(std::time::Duration::from_secs(10));
// stop cron
cron.stop();
}sourcepub fn stop(&self)
pub fn stop(&self)
Stop Cron.
ⓘ
let mut cron = cron::Cron::new();
let job_id = cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start();
cron.stop(); Examples found in repository?
examples/simple.rs (line 24)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let local_tz = Local::from_offset(&FixedOffset::east(7));
let mut cron = cron_tab::Cron::new(local_tz);
let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();
// start cron in background
cron.start();
cron.add_fn("* * * * * *", move || {
println!("add_fn {}", Local::now().to_string());
})
.unwrap();
// remove job_test
cron.remove(first_job_id);
std::thread::sleep(std::time::Duration::from_secs(10));
// stop cron
cron.stop();
}sourcepub fn start(&mut self)
pub fn start(&mut self)
Start cron. A thead will be spawn for schedule jobs
ⓘ
let mut cron = cron::Cron::new(Utc);
let job_id = cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start();Examples found in repository?
examples/simple.rs (line 11)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let local_tz = Local::from_offset(&FixedOffset::east(7));
let mut cron = cron_tab::Cron::new(local_tz);
let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();
// start cron in background
cron.start();
cron.add_fn("* * * * * *", move || {
println!("add_fn {}", Local::now().to_string());
})
.unwrap();
// remove job_test
cron.remove(first_job_id);
std::thread::sleep(std::time::Duration::from_secs(10));
// stop cron
cron.stop();
}sourcepub fn start_blocking(&mut self)
pub fn start_blocking(&mut self)
Run a loop for schedule jobs
Trait Implementations§
Auto Trait Implementations§
impl<Z> Freeze for Cron<Z>where
Z: Freeze,
impl<Z> RefUnwindSafe for Cron<Z>where
Z: RefUnwindSafe,
impl<Z> Send for Cron<Z>
impl<Z> Sync for Cron<Z>
impl<Z> Unpin for Cron<Z>where
Z: Unpin,
impl<Z> UnwindSafe for Cron<Z>where
Z: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)