refactor(api): _ndjson_line helper for streaming responses
This commit is contained in:
@@ -60,6 +60,17 @@ from cyclone.store import (
|
|||||||
log = logging.getLogger(__name__)
|
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
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||||
"""Initialize per-process resources (DB + EventBus) before the app
|
"""Initialize per-process resources (DB + EventBus) before the app
|
||||||
|
|||||||
Reference in New Issue
Block a user