diff --git a/shared/workspaces/test/test_remote_processing_service.py b/shared/workspaces/test/test_remote_processing_service.py index 845f1f8ee1226257aff9e4be51c0affa0a6f4a1d..a48fe15d86c25d4134ac85e6f6e057c700c84427 100644 --- a/shared/workspaces/test/test_remote_processing_service.py +++ b/shared/workspaces/test/test_remote_processing_service.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with Workspaces. If not, see <https://www.gnu.org/licenses/>. from datetime import datetime -from unittest.mock import patch +from unittest.mock import patch, MagicMock from test.test_workflow_info import FakeWorkflowInfo from workspaces.system.schema import AbstractFile @@ -92,6 +92,7 @@ class TestCapoInjector: @patch("pathlib.Path.unlink") @patch("glob.glob") @patch("os.listdir") + @patch("pathlib.Path.exists", MagicMock(return_value=True)) def test_clear_subspace(self, mock_os, mock_glob, mock_remove): injector.clear_subspace() assert mock_os.call_count == 1 diff --git a/shared/workspaces/workspaces/workflow/services/remote_processing_service.py b/shared/workspaces/workspaces/workflow/services/remote_processing_service.py index 9e23b5f345e25a7f2b32282f7d3890d080dfc087..33e115e9b4c3f49f26ebae14ca68e745cb3233a2 100644 --- a/shared/workspaces/workspaces/workflow/services/remote_processing_service.py +++ b/shared/workspaces/workspaces/workflow/services/remote_processing_service.py @@ -115,12 +115,17 @@ class CapoInjector: path.write_bytes(subspace.content) logger.info(f"Writing capo subspace file to {self.dir_path.__str__()}") - def clear_subspace(self): + def clear_subspace(self) -> bool: logger.info(f"Clearing capo subspace file from {self.dir_path.__str__()}...") - for file in os.listdir(self.dir_path): - if file.endswith(".properties"): - Path.unlink(self.dir_path / file) - - check = glob.glob("*.properties") - if check is None: - logger.info("Capo subspace cleared successfully.") + if self.dir_path.exists(): + for file in os.listdir(self.dir_path): + if file.endswith(".properties"): + Path.unlink(self.dir_path / file) + + check = glob.glob("*.properties") + if check is None: + logger.info("Capo subspace cleared successfully.") + return True + else: + logger.info(f"Directory {self.dir_path.__str__()} has already been cleaned.") + return False diff --git a/shared/workspaces/workspaces/workflow/services/workflow_service.py b/shared/workspaces/workspaces/workflow/services/workflow_service.py index b284005fd2a120b257b8a17858f325a71ae654ee..be1cce6d65c06f6722392e4c91ffdacdf698094b 100644 --- a/shared/workspaces/workspaces/workflow/services/workflow_service.py +++ b/shared/workspaces/workspaces/workflow/services/workflow_service.py @@ -1141,7 +1141,10 @@ class WorkflowMessageHandler: if injector.is_remote_workflow(): logger.debug("Cleaning remote workflow") - injector.clear_subspace() + result = injector.clear_subspace() + if result is False: + # the processing directory somehow disappeared, mark as cleaned to avoid further errors + request.cleaned = True @staticmethod def clean_workflow(request: WorkflowRequest):