Skip to main content

aurelin_framework/scheduling/
report.rs

1use super::BoxError;
2use crate::cache::Error as CacheError;
3
4/// Outcomes of all tasks due during one scheduler invocation, in registration order.
5#[derive(Debug)]
6pub struct RunReport {
7    pub(crate) tasks: Vec<TaskResult>,
8}
9
10impl RunReport {
11    /// The due tasks and their outcomes.
12    pub fn tasks(&self) -> &[TaskResult] {
13        &self.tasks
14    }
15
16    /// Whether any due task failed.
17    pub fn has_failures(&self) -> bool {
18        self.tasks.iter().any(|task| matches!(task.outcome, TaskOutcome::Failed(_)))
19    }
20}
21
22/// The result of one due task.
23#[derive(Debug)]
24pub struct TaskResult {
25    pub(crate) name: String,
26    pub(crate) outcome: TaskOutcome,
27}
28
29impl TaskResult {
30    /// Application-owned stable task name.
31    pub fn name(&self) -> &str {
32        &self.name
33    }
34    /// How this task completed.
35    pub fn outcome(&self) -> &TaskOutcome {
36        &self.outcome
37    }
38}
39
40/// An observable task outcome.
41#[derive(Debug)]
42pub enum TaskOutcome {
43    /// The callback completed successfully.
44    Succeeded,
45    /// Another execution held the overlap lock.
46    SkippedOverlap,
47    /// Another scheduler won the election for this occurrence.
48    SkippedElection,
49    /// The callback or its lock operation failed.
50    Failed(TaskFailure),
51}
52
53/// Failure at a task or cache-lock boundary.
54#[derive(Debug, thiserror::Error)]
55pub enum TaskFailure {
56    /// The cache failed while electing a scheduler.
57    #[error("could not acquire occurrence election lock: {0}")]
58    Election(#[source] CacheError),
59    /// The lock could not be acquired because the cache failed.
60    #[error("could not acquire overlap lock: {0}")]
61    Acquire(#[source] CacheError),
62    /// The application callback returned an error.
63    #[error("callback failed: {0}")]
64    Callback(#[source] BoxError),
65    /// The cache failed while releasing the lock.
66    #[error("could not release overlap lock: {0}")]
67    Release(#[source] CacheError),
68    /// The callback and lock release both failed.
69    #[error("callback failed: {callback}; could not release overlap lock: {release}")]
70    CallbackAndRelease {
71        /// Original callback error.
72        callback: BoxError,
73        /// Error encountered during cleanup.
74        release: CacheError,
75    },
76}