From c1119bdb934832f88aa4482c735fde87d9ac53a9 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Sat, 14 Dec 2024 13:00:06 +0100 Subject: [PATCH] Error handling when clean remote folder failed --- src/aiida_sssp_workflow/workflows/common.py | 11 +++++++++-- .../workflows/evaluate/_phonon_frequencies.py | 14 +++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/aiida_sssp_workflow/workflows/common.py b/src/aiida_sssp_workflow/workflows/common.py index 91289978..284ac863 100644 --- a/src/aiida_sssp_workflow/workflows/common.py +++ b/src/aiida_sssp_workflow/workflows/common.py @@ -1,4 +1,7 @@ +from builtins import ConnectionError from typing import Optional +from paramiko import ssh_exception + from aiida import orm @@ -40,8 +43,12 @@ def clean_workdir(node: orm.CalcJobNode) -> Optional[int]: # other subsequent calcjob as `parent_folder`, i.e PH calculation. cached_from = node.base.extras.get("_aiida_cached_from", None) if not cached_from: - node.outputs.remote_folder._clean() # pylint: disable=protected-access - return node.pk + try: + node.outputs.remote_folder._clean() # pylint: disable=protected-access + except ssh_exception.SSHException as exc: + raise ConnectionError("ssh error") from exc + else: + return node.pk else: return None diff --git a/src/aiida_sssp_workflow/workflows/evaluate/_phonon_frequencies.py b/src/aiida_sssp_workflow/workflows/evaluate/_phonon_frequencies.py index 31fbc7c1..b761a7d4 100644 --- a/src/aiida_sssp_workflow/workflows/evaluate/_phonon_frequencies.py +++ b/src/aiida_sssp_workflow/workflows/evaluate/_phonon_frequencies.py @@ -194,11 +194,15 @@ def finalize(self): """set ecutwfc and ecutrho""" if self.inputs.clean_workdir.value is True: - cleaned_calcs = operate_calcjobs( - self.node, operator=clean_workdir, all_same_nodes=False - ) - - if cleaned_calcs: + try: + cleaned_calcs = operate_calcjobs( + self.node, operator=clean_workdir, all_same_nodes=False + ) + except ConnectionError as exc: + self.logger.warning( + f"clean remote workdir folder {self.inputs.clean_workir} failed: {exc}" + ) + else: self.report( f"cleaned remote folders of calculations: {' '.join(map(str, cleaned_calcs))}" )