Aligned Task Scheduler
AlignedTaskScheduler is a scheduler built on the Tokio asynchronous runtime that runs tasks at precise minute intervals, with an optional offset in seconds. No matter when your application starts, it will first align to the next interval boundary before running tasks, ensuring tasks always trigger at exact times.
Features
- Precise Alignment: Run tasks at exact minute boundaries, suitable for scheduled reporting, syncing, or periodic checks.
- Configurable Offset: Add a few seconds of delay after the exact minute mark, allowing for minor adjustments to the schedule.
- Asynchronous Support: Built on Tokio’s async runtime, making it straightforward to perform I/O, network calls, or database operations in your scheduled tasks.
Installation
Add the dependency in your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["macros", "rt-multi-thread", "time"] }
Quick Start Example
In the example below, we create a scheduler that triggers a task every 5 minutes plus a 10-second offset. The task prints the aligned timestamp and the actual execution time:
use AlignedTaskScheduler;
use SystemTime;
async