| Crates.io | tokio-simple-fixed-scheduler |
| lib.rs | tokio-simple-fixed-scheduler |
| version | 0.1.0 |
| created_at | 2025-10-31 11:51:10.885326+00 |
| updated_at | 2025-10-31 11:51:10.885326+00 |
| description | Simple scheduler to emit events at a fixed interval with tokio |
| homepage | |
| repository | https://github.com/jacobtread/tokio-simple-fixed-scheduler |
| max_upload_size | |
| id | 1909945 |
| size | 27,248 |
Simple scheduler structure, accepts an event type along with events and produces a async stream that produces the event type each time the fixed interval occurs.
Uses tokio and chrono to sleep until the fixed interval is reached.
Providing the events as a stream makes managing them easier than other solutions which require calls backs and other complex handling.
use chrono::Utc;
use futures::StreamExt;
use tokio_simple_fixed_scheduler::{SchedulerEventStream, SchedulerQueueEvent};
use crate::database::{
DbPool,
secrets::{delete_excess_secret_versions, delete_scheduled_secrets},
};
mod scheduler;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub enum BackgroundEvent {
TestEventHourly,
TestEventMinutely,
}
#[tokio::main]
async fn main() {
let events = vec![
SchedulerQueueEvent {
event: BackgroundEvent::TestEventHourly,
interval: 60 * 60, // Run the event every hour
},
SchedulerQueueEvent {
event: BackgroundEvent::TestEventMinutely,
interval: 60, // Run the event every minute
},
];
let mut events = SchedulerEventStream::new(events);
while let Some(event) = events.next().await {
match event {
BackgroundEvent::TestEventHourly => {
// Run the hourly code
}
BackgroundEvent::TestEventMinutely => {
// Run the per minute code
}
}
}
}