summaryrefslogtreecommitdiffstats
path: root/src/http/sse.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/sse.rs')
-rw-r--r--src/http/sse.rs12
1 files changed, 0 insertions, 12 deletions
diff --git a/src/http/sse.rs b/src/http/sse.rs
index 561de33..e4a5e6a 100644
--- a/src/http/sse.rs
+++ b/src/http/sse.rs
@@ -4,10 +4,7 @@ use std::time::{Duration, Instant};
use crate::db::builds;
-/// How long a tail will wait for a build that never finishes. A viewer that
-/// outlives this gets a clean end and can reconnect.
const MAX_LIFETIME: Duration = Duration::from_secs(30 * 60);
-/// Silence between keepalives. Proxies drop idle streams well before this.
const KEEPALIVE: Duration = Duration::from_secs(10);
const POLL: Duration = Duration::from_millis(200);
@@ -15,9 +12,7 @@ pub struct LogTail {
path: PathBuf,
build_id: String,
db: crate::db::Db,
- /// Bytes of the file already forwarded.
offset: u64,
- /// SSE frames waiting to be handed to the caller.
out: std::collections::VecDeque<u8>,
started: Instant,
since_keepalive: Duration,
@@ -41,21 +36,16 @@ impl LogTail {
fn terminal(&self) -> bool {
match builds::get(&self.db, &self.build_id) {
Ok(Some(b)) => b.state.is_terminal(),
- // A build row that vanished is not going to produce more output.
Ok(None) => true,
- // A database hiccup should not end the stream; the next poll tries
- // again and the lifetime cap bounds the damage.
Err(_) => false,
}
}
- /// Pull whatever the build appended since the last poll and frame it as SSE.
fn pump(&mut self) {
let (bytes, grew) = read_from(&self.path, self.offset);
if grew {
self.offset += bytes.len() as u64;
for line in String::from_utf8_lossy(&bytes).lines() {
- // SSE: every line of payload needs its own `data:` prefix.
self.out.extend(format!("data: {line}\n\n").as_bytes());
}
self.since_keepalive = Duration::ZERO;
@@ -111,7 +101,6 @@ impl Read for LogTail {
}
}
-/// Read `path` from `offset`. Returns the bytes and whether the file grew.
fn read_from(path: &Path, offset: u64) -> (Vec<u8>, bool) {
let mut f = match std::fs::File::open(path) {
Ok(f) => f,
@@ -129,7 +118,6 @@ fn read_from(path: &Path, offset: u64) -> (Vec<u8>, bool) {
(buf, grew)
}
-/// A file served as-is, for static assets.
pub struct FileBody {
inner: std::io::Cursor<Vec<u8>>,
}