Skip to main content

stackless_core/engine/
progress.rs

1//! Step progress events during `up` — substrate-agnostic telemetry for
2//! agents and human operators.
3
4use super::plan::StepKind;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8pub enum StepProgressEvent {
9    Started,
10    Skipped,
11    Completed,
12    Failed,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct StepProgress {
17    pub event: StepProgressEvent,
18    pub instance: String,
19    pub step_id: String,
20    pub step_kind: StepKind,
21    pub node: String,
22    /// 1-based index within the plan.
23    pub index: usize,
24    pub total: usize,
25    /// Set on [`StepProgressEvent::Failed`] when a stable code is known.
26    pub code: Option<String>,
27    /// Wall-clock time of this event (Unix epoch milliseconds).
28    pub at_epoch_ms: i64,
29    /// Elapsed time since `step_started`, set on completed/failed/skipped.
30    pub duration_ms: Option<u64>,
31}
32
33pub trait ProgressSink {
34    fn on_step(&mut self, progress: StepProgress);
35    /// Called after admission, before any provisioning side effect.
36    fn on_admitted(&mut self, _record: &crate::state::InstanceRecord) {}
37    /// Cancellation is honored between steps, after resource handles are durable.
38    fn is_cancelled(&self) -> bool {
39        false
40    }
41}
42
43#[derive(Debug, Default)]
44pub struct NullProgress;
45
46impl ProgressSink for NullProgress {
47    fn on_step(&mut self, _progress: StepProgress) {}
48}
49
50pub fn epoch_ms() -> i64 {
51    std::time::SystemTime::now()
52        .duration_since(std::time::UNIX_EPOCH)
53        .map(|d| d.as_millis() as i64)
54        .unwrap_or(0)
55}