Crates.io | job_scheduler_ng |
lib.rs | job_scheduler_ng |
version | |
source | src |
created_at | 2022-05-20 16:34:58.133931+00 |
updated_at | 2025-04-13 16:18:55.301039+00 |
description | A simple cron-like job scheduling library for Rust (Updated since 2022). |
homepage | |
repository | https://github.com/BlackDex/job_scheduler |
max_upload_size | |
id | 590362 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A simple cron-like job scheduling library for Rust.
Forked from https://github.com/lholden/job_scheduler, thanks @lholden! This is a fork which i try to maintain and maybe even improve where needed.
2025-04-13 (v2.2.0):
2024-12-15 (v2.1.0 / unreleased):
2024-04-24 (v2.0.5):
const fn
log
function and always print the current thread id2023-02-01 (v2.0.4):
std::process::exit(0);
to produce a clean exit.2022-12-10 (v2.0.3):
2022-10-09 (v2.0.2):
Updated cron to v0.12.0
Set chrono v0.4.20 as minimum version to mitigate a know CVE.
Please see the Documentation for more details.
Be sure to add the job_scheduler_ng crate to your Cargo.toml
:
[dependencies]
job_scheduler_ng = "*"
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
* * * * * * *
Time is specified for UTC
and not your local timezone. Note that the year may
be omitted.
Comma separated values such as 5,8,10
represent more than one time value. So
for example, a schedule of 0 2,14,26 * * * *
would execute on the 2nd, 14th,
and 26th minute of every hour.
Ranges can be specified with a dash. A schedule of 0 0 * 5-10 * *
would
execute once per hour but only on day 5 through 10 of the month.
Day of the week can be specified as an abbreviation or the full name. A
schedule of 0 0 6 * * Sun,Sat
would execute at 6am on Sunday and Saturday.
A simple usage example:
extern crate job_scheduler_ng;
use job_scheduler_ng::{JobScheduler, Job};
use std::time::Duration;
fn main() {
let mut sched = JobScheduler::new();
sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
println!("I get executed every 10 seconds!");
}));
loop {
sched.tick();
std::thread::sleep(Duration::from_millis(500));
}
}
Setting a custom timezone other then the default UTC.
Any Tz::Offset
provided by chrono will work.
use chrono::Local;
use job_scheduler_ng::{JobScheduler, Job};
use core::time::Duration;
fn main() {
let mut sched = JobScheduler::new();
let local_tz = chrono::Local::now();
sched.set_timezone(*local_tz.offset());
sched.add(Job::new("0 5 13 * * *".parse().unwrap(), || {
println!("I get executed every day 13:05 local time!");
}));
loop {
sched.tick();
std::thread::sleep(Duration::from_millis(500));
}
}
JobScheduler is licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Please see the CONTRIBUTING file for more information.