From d1cd1a5a593323ba74d8a8053bab32e4a7d903a1 Mon Sep 17 00:00:00 2001 From: Marco Donadoni Date: Wed, 7 Aug 2024 15:33:49 +0200 Subject: [PATCH] fix(reana-admin): skip retention rules for deleted workspaces (#697) Closes reanahub/reana-server#693 --- reana_server/reana_admin/cli.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/reana_server/reana_admin/cli.py b/reana_server/reana_admin/cli.py index 2cbe0fea..0fbf07ad 100644 --- a/reana_server/reana_admin/cli.py +++ b/reana_server/reana_admin/cli.py @@ -10,6 +10,7 @@ import datetime import logging +from pathlib import Path import secrets import sys import traceback @@ -850,6 +851,17 @@ def retention_rules_apply( click.echo("No rules to be applied!") for rule in pending_rules: + if not Path(rule.workflow.workspace_path).exists(): + # workspace was deleted, set rule as if it was already applied + click.secho( + f"Workspace {rule.workflow.workspace_path} of rule {rule.id_} does not exist, " + "setting the status to `applied`", + fg="red", + ) + update_workspace_retention_rules( + [rule], WorkspaceRetentionRuleStatus.applied + ) + continue # if there are errors, the status of the rule will be reset to `active` # so that the rule will be applied again at the next execution of the cronjob next_status = WorkspaceRetentionRuleStatus.active