Crates.io | croner-scheduler |
lib.rs | croner-scheduler |
version | 0.0.12 |
source | src |
created_at | 2023-12-05 23:42:09.618576 |
updated_at | 2023-12-21 19:51:41.435957 |
description | A threaded cron job scheduler library for Rust |
homepage | https://github.com/hexagon/croner-scheduler-rust |
repository | https://github.com/hexagon/croner-scheduler-rust |
max_upload_size | |
id | 1059515 |
size | 28,241 |
Croner Scheduler is a standalone Rust library focused on scheduling tasks based on cron patterns. This library is a stand-alone part of the Croner project and is designed for developers who want a lightweight and efficient tool for threaded task scheduling using the familiar cron syntax.
For more information about cron pattern parsing and evaluation, please refer to the Croner crate.
croner
.Ensure you have Rust installed on your machine. If not, you can get it from the official Rust website.
Add croner-scheduler
, croner
and chrono
to your Cargo.toml
dependencies:
[dependencies]
croner-scheduler = "0.0.12"
croner = "2.0.3"
chrono = "0.4.31"
Here's a quick example to get you started with scheduling a task:
use chrono::Local;
use croner_scheduler::{CronScheduler, SchedulerResult};
use croner::Cron;
use std::thread;
fn main() {
// Schedule a task at even seconds
let cron: Cron = "0/2 * * * * *".parse().expect("Invalid cron expression");
let mut scheduler = CronScheduler::new(cron);
// The trigger closure must be set up to accept an optional context
scheduler.start(|_: Option<&()>| {
println!("Task 1 triggered at {:?}", Local::now());
});
// The tasks can be paused, resumed, or stopped as needed
// scheduler.pause();
// scheduler.resume();
// scheduler.stop();
// Loop to keep the main process alive
// - You need to supply a time-zoned "now" to tick, so that
// croner knows which timezone to match the pattern against.
// Using Local in this example.
while scheduler.tick(Local::now()) != SchedulerResult::Dead {
// Sleep for a short duration to prevent busy waiting
thread::sleep(std::time::Duration::from_millis(300));
}
}
For detailed documentation and examples, please visit Croner Scheduler on docs.rs.
We welcome contributions! Please feel free to submit a pull request or open an issue.
This project is licensed under the MIT License - see the LICENSE.md file for details.
Please note that Croner Scheduler is currently in its early stages of development. As such, the API is subject to change in future releases, adhering to semantic versioning principles. We recommend keeping this in mind when integrating Croner Scheduler into your projects.
If you have any questions or feedback, please open an issue in the repository, and we'll get back to you as soon as possible.