Crates.io | rusty-cron-scheduler |
lib.rs | rusty-cron-scheduler |
version | 0.1.0 |
source | src |
created_at | 2024-07-31 06:14:54.473563 |
updated_at | 2024-07-31 06:14:54.473563 |
description | Simple scheduler that executes function pointers following a cron string |
homepage | |
repository | https://github.com/MASACR99/rusty-scheduler |
max_upload_size | |
id | 1320668 |
size | 47,660 |
Lightweight and performant library to use cron formatted strings to trigger function pointers.
rusty-scheduler is a simple library made to receive function pointers and cron strings and take care of when to execute them with some configurability to better adapt it to most situations, it's a very lightweight implementation and thus is limited to currently triggering simple functions without parameters, I'm currently investigating and prototyping the possibility of adding functions with parameters.
The main scheduler thread runs in a separate thread that starts when startup() is called for the scheduler, you may still use add_task and remove_task after starting the scheduler since a Mutex takes cares of any synchronization issue.
Another important thing, if the execution of the task doesn't end before it's next execution is due it will skip that execution, there's currently no parallel triggering, this will be configurable in a later release.
And the execution of the tasks is done by a separate thread on the background, so yes, every task you add will end up generating a thread when it executes, but never more than 1 (for now), that's something to keep in mind.
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.
You may also configure 2 parameters:
The default values are 1000 for the scheduler wait and 250 for the threshold, but I encorage you to test different configurations to better adapt the scheduler to your needs.
Should be as easy as cargo add rusty-scheduler
To start a new scheduler use Scheduler::new(
add_task will return a Uuid that you can use to call remove_task with, which will delete the task from the scheduler.
Finally call startup() on the scheduler to start the scheduler thread, which will do the heavy lifting of generating the threds that will execute your functions
You may still add or remove tasks after startup and the same scheduler thread will keep them tracked
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.