From 8d938902b5ff8f2fca650f0cbb555caea3b75878 Mon Sep 17 00:00:00 2001 From: Jamey Huffnagle Date: Mon, 22 Apr 2024 16:04:59 -0400 Subject: [PATCH] fix(robot-server): notify /runs when a non-current run is deleted (#14974) Closes RQA-2599 --- .../robot_server/runs/run_data_manager.py | 3 +- .../publishers/runs_publisher.py | 30 ++++++++++--------- .../publishers/test_runs_publisher.py | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/robot-server/robot_server/runs/run_data_manager.py b/robot-server/robot_server/runs/run_data_manager.py index 154a1584823..8548104911b 100644 --- a/robot-server/robot_server/runs/run_data_manager.py +++ b/robot-server/robot_server/runs/run_data_manager.py @@ -284,7 +284,8 @@ async def delete(self, run_id: str) -> None: """ if run_id == self._engine_store.current_run_id: await self._engine_store.clear() - await self._runs_publisher.clean_up_current_run() + + await self._runs_publisher.clean_up_run(run_id=run_id) self._run_store.remove(run_id=run_id) diff --git a/robot-server/robot_server/service/notifications/publishers/runs_publisher.py b/robot-server/robot_server/service/notifications/publishers/runs_publisher.py index b6744fbc90a..fef23c8a875 100644 --- a/robot-server/robot_server/service/notifications/publishers/runs_publisher.py +++ b/robot-server/robot_server/service/notifications/publishers/runs_publisher.py @@ -71,12 +71,12 @@ async def initialize( ) self._engine_state_slice = EngineStateSlice() - await self._publish_runs_advise_refetch_async() + await self._publish_runs_advise_refetch_async(run_id=run_id) - async def clean_up_current_run(self) -> None: - """Publish final refetch and unsubscribe flags.""" - await self._publish_runs_advise_refetch_async() - await self._publish_runs_advise_unsubscribe_async() + async def clean_up_run(self, run_id: str) -> None: + """Publish final refetch and unsubscribe flags for the given run.""" + await self._publish_runs_advise_refetch_async(run_id=run_id) + await self._publish_runs_advise_unsubscribe_async(run_id=run_id) async def _publish_current_command(self) -> None: """Publishes the equivalent of GET /runs/:runId/commands?cursor=null&pageLength=1.""" @@ -84,20 +84,20 @@ async def _publish_current_command(self) -> None: topic=Topics.RUNS_CURRENT_COMMAND ) - async def _publish_runs_advise_refetch_async(self) -> None: + async def _publish_runs_advise_refetch_async(self, run_id: str) -> None: """Publish a refetch flag for relevant runs topics.""" + await self._client.publish_advise_refetch_async(topic=Topics.RUNS) + if self._run_hooks is not None: - await self._client.publish_advise_refetch_async(topic=Topics.RUNS) await self._client.publish_advise_refetch_async( - topic=f"{Topics.RUNS}/{self._run_hooks.run_id}" + topic=f"{Topics.RUNS}/{run_id}" ) - async def _publish_runs_advise_unsubscribe_async(self) -> None: + async def _publish_runs_advise_unsubscribe_async(self, run_id: str) -> None: """Publish an unsubscribe flag for relevant runs topics.""" - if self._run_hooks is not None: - await self._client.publish_advise_unsubscribe_async( - topic=f"{Topics.RUNS}/{self._run_hooks.run_id}" - ) + await self._client.publish_advise_unsubscribe_async( + topic=f"{Topics.RUNS}/{run_id}" + ) async def _handle_current_command_change(self) -> None: """Publish a refetch flag if the current command has changed.""" @@ -121,7 +121,9 @@ async def _handle_engine_status_change(self) -> None: and self._engine_state_slice.state_summary_status != current_state_summary.status ): - await self._publish_runs_advise_refetch_async() + await self._publish_runs_advise_refetch_async( + run_id=self._run_hooks.run_id + ) self._engine_state_slice.state_summary_status = ( current_state_summary.status ) diff --git a/robot-server/tests/service/notifications/publishers/test_runs_publisher.py b/robot-server/tests/service/notifications/publishers/test_runs_publisher.py index 29797dbf83a..a889664cbee 100644 --- a/robot-server/tests/service/notifications/publishers/test_runs_publisher.py +++ b/robot-server/tests/service/notifications/publishers/test_runs_publisher.py @@ -71,7 +71,7 @@ async def test_clean_up_current_run( """It should publish to appropriate topics at the end of a run.""" await runs_publisher.initialize("1234", AsyncMock(), AsyncMock()) - await runs_publisher.clean_up_current_run() + await runs_publisher.clean_up_run(run_id="1234") notification_client.publish_advise_refetch_async.assert_any_await(topic=Topics.RUNS) notification_client.publish_advise_refetch_async.assert_any_await(