refactor(config)!: Move scheduler out of device_manager

Due to changes made in mlua the new scheduler is much simpler. It also
had no real business being part of the device manager, so it has now been
moved to be part of the returned config.
This commit is contained in:
2025-10-17 04:29:14 +02:00
parent d1e7988117
commit 46c32c3605
13 changed files with 224 additions and 138 deletions

28
src/schedule.rs Normal file
View File

@@ -0,0 +1,28 @@
use std::collections::HashMap;
use std::pin::Pin;
use tokio_cron_scheduler::{Job, JobScheduler, JobSchedulerError};
pub async fn start_scheduler(
schedule: HashMap<String, mlua::Function>,
) -> Result<(), JobSchedulerError> {
let scheduler = JobScheduler::new().await?;
for (s, f) in schedule {
let job = {
move |_uuid, _lock| -> Pin<Box<dyn Future<Output = ()> + Send>> {
let f = f.clone();
Box::pin(async move {
f.call_async::<()>(()).await.unwrap();
})
}
};
let job = Job::new_async(s, job)?;
scheduler.add(job).await?;
}
scheduler.start().await
}