Skip to content

Commit b1a5348

Browse files
core: services: commander: main: Add new remove_log_stream
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
1 parent 0304047 commit b1a5348

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

core/services/commander/main.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#! /usr/bin/env python3
2+
import json
23
import logging
34
import os
45
import shutil
@@ -12,10 +13,10 @@
1213
import uvicorn
1314
from commonwealth.utils.apis import GenericErrorHandlingRoute
1415
from commonwealth.utils.commands import run_command
15-
from commonwealth.utils.general import delete_everything
16+
from commonwealth.utils.general import delete_everything, delete_everything_stream
1617
from commonwealth.utils.logs import InterceptHandler, init_logger
1718
from fastapi import FastAPI, HTTPException, status
18-
from fastapi.responses import HTMLResponse
19+
from fastapi.responses import HTMLResponse, StreamingResponse
1920
from fastapi_versioning import VersionedFastAPI, version
2021
from loguru import logger
2122

@@ -257,6 +258,19 @@ def setup_ssh() -> None:
257258
logger.info("SSH setup done")
258259

259260

261+
@app.post("/services/remove_log_stream", status_code=status.HTTP_200_OK)
262+
@version(1, 0)
263+
async def remove_log_services_stream(i_know_what_i_am_doing: bool = False) -> StreamingResponse:
264+
"""Stream the deletion of log files, providing real-time updates about each file being deleted."""
265+
check_what_i_am_doing(i_know_what_i_am_doing)
266+
267+
async def generate():
268+
async for info in delete_everything_stream(Path(LOG_FOLDER_PATH)):
269+
yield json.dumps(info) + "\n"
270+
271+
return StreamingResponse(generate(), media_type="application/x-ndjson")
272+
273+
260274
if __name__ == "__main__":
261275
setup_ssh()
262276
# Register ssh client and remove message from the following commands

0 commit comments

Comments
 (0)