Skip to main content

kernel/jobs/
event.rs

1//! The two event vocabularies: what a job runner streams (`JobRuntimeEvent`) and
2//! what the scheduler publishes to observers (`JobEvent`).
3
4use super::job::JobProgress;
5
6/// One item a job runtime (image generation) streams back. The sidecar job pump
7/// emits `Started`/`Progress`/`Preview`/`Result`; `Status` and `Artifacts` are
8/// added by the scheduler layer that wraps the pump.
9#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10pub enum JobRuntimeEvent {
11    /// A free-text status notice (emitted by the scheduler, not the pump).
12    Status(String),
13    /// Generation has begun.
14    Started,
15    /// Progress through a fixed number of steps.
16    Progress { step: i64, total_steps: i64 },
17    /// An intermediate preview image.
18    Preview(Vec<u8>),
19    /// A finished output artifact and the file extension it should carry.
20    Result {
21        data: Vec<u8>,
22        file_extension: String,
23    },
24    /// The set of artifact paths a job produced (emitted by the scheduler).
25    Artifacts(Vec<String>),
26}
27
28/// What the scheduler publishes to `events(id)` observers. Coarser than the
29/// runtime stream: it collapses the runner's ticks into the observable state.
30#[derive(Debug, Clone, PartialEq)]
31pub enum JobEvent {
32    /// The job is queued, optionally with a human reason for the wait.
33    Queued { reason: Option<String> },
34    /// The job has passed admission and is preparing.
35    Preparing,
36    /// A free-text status notice.
37    Status(String),
38    /// The job is actively running.
39    Running,
40    /// Monotone progress.
41    Progress(JobProgress),
42    /// An intermediate preview image.
43    Preview(Vec<u8>),
44    /// The job finished, with its result artifact ids.
45    Done { result: Vec<String> },
46    /// The job failed, with a message.
47    Failed { message: String },
48    /// The job was cancelled.
49    Cancelled,
50}