pub struct Cron<Z>where
Z: TimeZone + Sync + Send + 'static,
Z::Offset: Send,{ /* private fields */ }
Implementations§
source§impl<Z> Cron<Z>where
Z: TimeZone + Sync + Send + 'static,
Z::Offset: Send,
impl<Z> Cron<Z>where Z: TimeZone + Sync + Send + 'static, Z::Offset: Send,
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>where
T: 'static + Fn() + Send + Sync,
pub fn add_fn<T>(&mut self, spec: &str, f: T) -> Result<usize>where T: 'static + Fn() + Send + Sync,
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