diff --git a/yapapi/events.py b/yapapi/events.py index 6e3b46910..128bc8f54 100644 --- a/yapapi/events.py +++ b/yapapi/events.py @@ -521,6 +521,9 @@ class CommandStdOut(CommandEvent): class CommandStdErr(CommandEvent): output: str +@attr.s(auto_attribs=True, repr=False) +class CommandProgress(CommandEvent): + message: str @attr.s(auto_attribs=True, repr=False) class TaskAccepted(TaskEvent): diff --git a/yapapi/log.py b/yapapi/log.py index c539ddba3..bc5c1dc8f 100644 --- a/yapapi/log.py +++ b/yapapi/log.py @@ -164,6 +164,7 @@ def enable_default_logger( events.CommandStdOut: "Command stdout", events.CommandStdErr: "Command stderr", events.CommandExecuted: "Script command executed", + events.CommandProgress: "Script command progress update", events.GettingResults: "Getting script results", events.ScriptFinished: "Script finished", events.TaskAccepted: "Task accepted", diff --git a/yapapi/rest/activity.py b/yapapi/rest/activity.py index 8b13e605d..1a4541063 100644 --- a/yapapi/rest/activity.py +++ b/yapapi/rest/activity.py @@ -283,8 +283,7 @@ async def __aiter__(self) -> AsyncIterator[CommandEventData]: results = await self._get_results(timeout=min(timeout, 5)) any_new: bool = False - results = results[last_idx:] - for result in results: + for result in results[last_idx:]: any_new = True assert last_idx == result.index, f"Expected {last_idx}, got {result.index}" @@ -300,6 +299,18 @@ async def __aiter__(self) -> AsyncIterator[CommandEventData]: last_idx = result.index + 1 if result.is_batch_finished: break + + current_idx = last_idx - 1 + if current_idx >= 0: + current = results[current_idx] + + if current.message is not None: + kwargs = dict( + cmd_idx=current.index, + message=current.message, + ) + yield events.CommandProgress, kwargs + if not any_new: delay = min(3, max(0, self.seconds_left())) await asyncio.sleep(delay)