Crates.io | rusty-cron |
lib.rs | rusty-cron |
version | 0.8.0 |
source | src |
created_at | 2024-07-30 12:56:56.225653 |
updated_at | 2024-07-30 12:56:56.225653 |
description | Lightweight and performant library to parse cron format strings and return the remaining miliseconds to execute. Accepts both 5 and 6 parameters (5 for minutes and up and 6 for seconds) |
homepage | |
repository | https://github.com/MASACR99/rusty-cron |
max_upload_size | |
id | 1319776 |
size | 50,775 |
Lightweight and performant library to parse cron format strings and return the remaining miliseconds to execute.
rusty-cron is a simple library made to parse cron formatted strings and return the remaining milliseconds to the next execution, either using current time or a given one, it's made to be very quick at the cost of being a bit more heavy on memory, but it shouldn't be a problem for most applications.
Currently allows for either a 5 or 6 tokens cron formated string depending on if you need the precision to go up to minutes or seconds respectively. It also allows all normal tokens to be used in the string, those are:
You can also mix and match those in some ways, checkout https://crontab.guru/ for an amazing explanation on what does your cron do.
Should be as easy as cargo install rusty_cron
Simply add the use rusty_cron::Cron and use Cron::parse_time() with your cron string (I recommend https://crontab.guru/ to validate your strings and create new ones),
and, optionally, a second parameter DateTime
That'll return a result, with a string with the error message or the milliseconds remaining to the next theoretical execution. If what you want is for a task to be triggered periodically, have a look at rusty-scheduler, it uses this same cron string format to automatically execute functions.
If you feel like something is missing, could be improved or needs to be changed let me know on a ticket or just start a pull request and I'll try to have a look at it asap.