This is a library for running periodic tasks:
Job
trait for your domain specific data type T
, which represents the task to be runT
via a tokio::sync::mpsc::channel
to periodic_do::loop_forever
T
for two things:
T
up to be run? If so, run it and update the job stateT
reached a terminal state? In which case it will be forgottenUsable, but has rough edges, evaluate before using it in production.
```rust use tokio;
async fn main() -> Result<(), Error> { let (sender, receiver) = tokio::sync::mpsc::channel(1000);
let unfinishedjobs = loadunfinishedjobsfrom_database().await?;
// Start the scheduler let capacity = periodicdo::Capacity { maxrunningjobs: 10, sweepsleepsecondsdefault: 5, sweepsleepsecondsmin: 1, sweepsleepsecondsmax: 60, }; tokio::spawn(async move { periodicdo::loopforever( capacity, receiver, unfinished_jobs ).await });
loop {
// T implements Job
trait
let sometask: T = getataskfromsomewhere().await;
sender.send(some_task).await
}
Ok(()) } ```