use async_trait::async_trait;
use chrono::{DateTime, Utc};
#[derive(Debug, Clone)]
pub struct LogChunk {
pub workflow_id: String,
pub definition_id: String,
pub step_id: usize,
pub step_name: String,
pub stream: LogStreamType,
pub data: Vec<u8>,
pub timestamp: DateTime<Utc>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogStreamType {
Stdout,
Stderr,
}
#[async_trait]
pub trait LogSink: Send + Sync {
async fn write_chunk(&self, chunk: LogChunk);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn log_stream_type_equality() {
assert_eq!(LogStreamType::Stdout, LogStreamType::Stdout);
assert_ne!(LogStreamType::Stdout, LogStreamType::Stderr);
}
#[test]
fn log_chunk_clone() {
let chunk = LogChunk {
workflow_id: "wf-1".to_string(),
definition_id: "def-1".to_string(),
step_id: 0,
step_name: "build".to_string(),
stream: LogStreamType::Stdout,
data: b"hello\n".to_vec(),
timestamp: Utc::now(),
};
let cloned = chunk.clone();
assert_eq!(cloned.workflow_id, "wf-1");
assert_eq!(cloned.stream, LogStreamType::Stdout);
assert_eq!(cloned.data, b"hello\n");
}
}