feat: add ecc2 output time filters

This commit is contained in:
Affaan Mustafa
2026-04-09 04:10:51 -07:00
parent 077f46b777
commit 3b700c8715
4 changed files with 230 additions and 70 deletions

View File

@@ -32,6 +32,31 @@ impl OutputStream {
pub struct OutputLine {
pub stream: OutputStream,
pub text: String,
pub timestamp: String,
}
impl OutputLine {
pub fn new(
stream: OutputStream,
text: impl Into<String>,
timestamp: impl Into<String>,
) -> Self {
Self {
stream,
text: text.into(),
timestamp: timestamp.into(),
}
}
pub fn with_current_timestamp(stream: OutputStream, text: impl Into<String>) -> Self {
Self::new(stream, text, chrono::Utc::now().to_rfc3339())
}
pub fn occurred_at(&self) -> Option<chrono::DateTime<chrono::Utc>> {
chrono::DateTime::parse_from_rfc3339(&self.timestamp)
.ok()
.map(|timestamp| timestamp.with_timezone(&chrono::Utc))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -70,10 +95,7 @@ impl SessionOutputStore {
}
pub fn push_line(&self, session_id: &str, stream: OutputStream, text: impl Into<String>) {
let line = OutputLine {
stream,
text: text.into(),
};
let line = OutputLine::with_current_timestamp(stream, text);
{
let mut buffers = self.lock_buffers();
@@ -145,5 +167,6 @@ mod tests {
assert_eq!(event.session_id, "session-1");
assert_eq!(event.line.stream, OutputStream::Stderr);
assert_eq!(event.line.text, "problem");
assert!(event.line.occurred_at().is_some());
}
}

View File

@@ -961,9 +961,9 @@ impl StateStore {
pub fn get_output_lines(&self, session_id: &str, limit: usize) -> Result<Vec<OutputLine>> {
let mut stmt = self.conn.prepare(
"SELECT stream, line
"SELECT stream, line, timestamp
FROM (
SELECT id, stream, line
SELECT id, stream, line, timestamp
FROM session_output
WHERE session_id = ?1
ORDER BY id DESC
@@ -976,11 +976,13 @@ impl StateStore {
.query_map(rusqlite::params![session_id, limit as i64], |row| {
let stream: String = row.get(0)?;
let text: String = row.get(1)?;
let timestamp: String = row.get(2)?;
Ok(OutputLine {
stream: OutputStream::from_db_value(&stream),
Ok(OutputLine::new(
OutputStream::from_db_value(&stream),
text,
})
timestamp,
))
})?
.collect::<Result<Vec<_>, _>>()?;