Skip to main content

aurelin_framework/scheduling/
commands.rs

1//! Process-facing scheduler command.
2
3use super::{Schedule, TaskOutcome};
4
5/// Run due tasks, report failures to stderr, and signal a failing process status.
6pub async fn run(schedule: &Schedule) -> Result<(), CommandError> {
7    let report = schedule.run().await;
8    for task in report.tasks() {
9        if let TaskOutcome::Failed(error) = task.outcome() {
10            eprintln!("scheduled task [{}] failed: {error}", task.name());
11        }
12    }
13    if report.has_failures() { Err(CommandError) } else { Ok(()) }
14}
15
16/// At least one due scheduled task failed.
17#[derive(Debug, thiserror::Error)]
18#[error("one or more scheduled tasks failed")]
19pub struct CommandError;