Skip to content

Commit

Permalink
[resotocore][feat] Progress end before Task end (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Sep 5, 2023
1 parent 280076e commit d4914a6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
10 changes: 9 additions & 1 deletion resotocore/resotocore/task/task_description.py
Expand Up @@ -663,7 +663,15 @@ def current_step_done(self) -> bool:
return False

def commands_to_execute(self) -> Sequence[TaskCommand]:
return [SendMessage(self.event)]
messages = []
task = self.instance
# make sure to send the remaining progress message before the end message
if task.not_emitted_progress() is not None:
pr = task.progress_json()
data = dict(workflow=task.descriptor.name, task=task.id, message=pr)
messages.append(SendMessage(Event(CoreMessage.ProgressMessage, freeze(data))))
messages.append(SendMessage(self.event))
return messages

def step_started(self) -> None:
super().step_started()
Expand Down
7 changes: 0 additions & 7 deletions resotocore/resotocore/task/task_handler.py
Expand Up @@ -563,13 +563,6 @@ async def check_running_tasks(self) -> None:
In case there is progress not emitted, it is send to the message bus.
"""
for task in list(self.tasks.values()):
# check if there is any pending progress update to emit
if task.not_emitted_progress() is not None:
await self.message_bus.emit_event(
CoreMessage.ProgressMessage,
{"workflow": task.descriptor.name, "task": task.id, "message": task.progress_json()},
)

# check if active tasks are overdue
if task.is_active:
if task.current_state.check_timeout():
Expand Down
2 changes: 2 additions & 0 deletions resotocore/tests/resotocore/message_bus_test.py
Expand Up @@ -21,6 +21,7 @@
from resotocore.model.typed_model import to_js, from_js
from resotocore.util import AnyT, utc, first
from resotolib.core.progress import ProgressDone, Progress
from resotolib.utils import freeze


async def wait_for_message(
Expand Down Expand Up @@ -78,6 +79,7 @@ def test_message_serialization() -> None:
subsctiber_id = SubscriberId("sub")
now = datetime(2022, 10, 23, 12, 0, 0, 0, timezone.utc)
roundtrip(Event("test", {"a": "b", "c": 1, "d": "bla"}))
roundtrip(Event("test", freeze({"a": "b", "c": {"a": 1, "d": "bla"}})))
roundtrip(Action("test", task_id, "step_name"))
roundtrip(Action("test", task_id, "step_name", {"test": 1}))
roundtrip(ActionDone("test", task_id, "step_name", subsctiber_id))
Expand Down
2 changes: 1 addition & 1 deletion resotocore/tests/resotocore/task/task_description_test.py
Expand Up @@ -146,7 +146,7 @@ def test_complete_workflow(
assert len(events) == 0
assert wi.current_step.name == "done"
events = wi.handle_done(ActionDone("done", wi.id, "done", s2.id))
assert len(events) == 1
assert len(events) == 2
assert wi.progress.percentage == 100
assert wi.is_active is False

Expand Down

0 comments on commit d4914a6

Please sign in to comment.