1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Represents a job flowing through a pipeline.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Job {
/// ULID generated by Bria or from config id_field.
pub id: String,
/// The source that produced this job.
pub source: String,
/// The job payload as a JSON value.
pub payload: serde_json::Value,
/// Optional correlation key for multi-source merging.
#[serde(skip_serializing_if = "Option::is_none")]
pub correlation_key: Option<String>,
/// Labels attached by the source and/or pipeline configuration.
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub labels: HashMap<String, String>,
}
/// Result of executing a single pipeline step.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StepResult {
/// Captured stdout (if mode was capture).
#[serde(skip_serializing_if = "Option::is_none")]
pub stdout: Option<String>,
/// Captured stderr (if mode was capture).
#[serde(skip_serializing_if = "Option::is_none")]
pub stderr: Option<String>,
/// Exit code of the subprocess.
pub exit_code: i32,
/// Duration of the step in milliseconds.
pub duration_ms: u64,
/// Attempt number (1-indexed).
pub attempt: u32,
/// Named outputs extracted from stdout (JSON parse).
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub outputs: HashMap<String, serde_json::Value>,
}
/// The full context passed through a pipeline's steps.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Context {
/// The job being processed.
pub job: Job,
/// Results of each step, keyed by step id.
pub steps: HashMap<String, StepResult>,
}
impl Context {
/// Create a new context from a job.
pub fn new(job: Job) -> Self {
Self {
job,
steps: HashMap::new(),
}
}
/// Insert a step result.
pub fn set_step(&mut self, id: String, result: StepResult) {
self.steps.insert(id, result);
}
}
/// Result of a completed pipeline run.
#[derive(Debug, Clone, Serialize)]
pub struct PipelineResult {
/// The pipeline that ran.
pub pipeline_id: String,
/// The job that was processed.
pub job: Job,
/// Status: "success" or "failure".
pub status: String,
/// Total wall-clock duration in milliseconds.
pub duration_ms: u64,
/// Per-step results.
pub steps: HashMap<String, StepResult>,
/// Timestamp of completion (ISO-8601).
pub occurred_at: String,
}
impl PipelineResult {
pub fn success(
pipeline_id: String,
job: Job,
steps: HashMap<String, StepResult>,
duration_ms: u64,
) -> Self {
Self {
pipeline_id,
job,
status: "success".to_string(),
duration_ms,
steps,
occurred_at: chrono::Utc::now().to_rfc3339(),
}
}
pub fn failure(
pipeline_id: String,
job: Job,
steps: HashMap<String, StepResult>,
duration_ms: u64,
) -> Self {
Self {
pipeline_id,
job,
status: "failure".to_string(),
duration_ms,
steps,
occurred_at: chrono::Utc::now().to_rfc3339(),
}
}
}