[−][src]Crate cron_tab
CronTab
A cron job library for Rust.
Usage
Add cron_tab crate to your Cargo.toml
:
[dependencies]
cron_tab = "0.1.0"
Creating a schedule for a job is done using the FromStr
impl for the
Schedule
type of the cron library.
The scheduling format is as follows:
sec min hour day of month month day of week year
* * * * * * *
A simple example:
ⓘThis example is not tested
extern crate cron_tab; use chrono::{FixedOffset, Local, TimeZone, Utc}; fn main() { let local_tz = Local::from_offset(&FixedOffset::east(7)); let utc_tz = Utc; let mut cron = cron_tab::Cron::new(utc_tz); let job_test_id = cron.add_fn("* * * * * * *", test).unwrap(); cron.start(); std::thread::sleep(std::time::Duration::from_secs(2)); let anonymous_job_id = cron .add_fn("* * * * * *", || { println!("anonymous fn"); }) .unwrap(); // remove job_test cron.remove(job_test_id); loop { std::thread::sleep(std::time::Duration::from_secs(2)); } } fn test() { println!("now: {}", Local::now().to_string()); }
Structs
Cron | |
Entry | Entry wrap data about the job |
Enums
CronError |