refactor(api): _ndjson_line helper for streaming responses

This commit is contained in:
Tyler
2026-06-20 15:52:05 -06:00
parent 8bcb23c78d
commit 3ab1de23d3
+11
View File
@@ -60,6 +60,17 @@ from cyclone.store import (
log = logging.getLogger(__name__)
def _ndjson_line(event: dict) -> bytes:
"""Serialize one event dict as a single NDJSON line (UTF-8, trailing ``\\n``).
Used by the live-tail streaming endpoints to emit a uniform wire format
that the frontend ``tail-stream.ts`` parser can split on newlines.
Compact separators keep each line small and avoid ambiguity with embedded
whitespace.
"""
return (json.dumps(event, separators=(",", ":")) + "\n").encode("utf-8")
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
"""Initialize per-process resources (DB + EventBus) before the app