From ff1d9188413ce421c83e19c33a5f11191aee3d94 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Thu, 8 Aug 2024 16:00:03 +0200 Subject: [PATCH] user actions: fix approve and restart --- backoffice/backoffice/workflows/airflow_utils.py | 12 +++++++++--- backoffice/backoffice/workflows/api/views.py | 4 +++- .../author/author_create/author_create_approved.py | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backoffice/backoffice/workflows/airflow_utils.py b/backoffice/backoffice/workflows/airflow_utils.py index 2975f880..bdb6e577 100644 --- a/backoffice/backoffice/workflows/airflow_utils.py +++ b/backoffice/backoffice/workflows/airflow_utils.py @@ -55,13 +55,19 @@ def restart_failed_tasks(workflow_id, workflow_type): :param workflow_type: type of workflow to retrieve :returns: request response """ - - dag_id = find_failed_dag(workflow_id, workflow_type) + print("workflow is is") + print(str(workflow_id)) + dag_id = find_failed_dag(str(workflow_id), workflow_type) + if dag_id is None: + return JsonResponse({"message": "There are no failing tasks, skipping restart"}) + + print("dag_id is") + print(dag_id) # assumes current task is one of the failed tasks data = { "dry_run": False, "dag_run_id": str(workflow_id), - "reset_dag_runs": False, + "reset_dag_runs": True, "only_failed": True, } diff --git a/backoffice/backoffice/workflows/api/views.py b/backoffice/backoffice/workflows/api/views.py index 85125b29..ca78ae8e 100644 --- a/backoffice/backoffice/workflows/api/views.py +++ b/backoffice/backoffice/workflows/api/views.py @@ -194,7 +194,9 @@ def restart(self, request, pk=None): workflow = Workflow.objects.get(id=pk) if request.data.get("restart_current_task"): - return airflow_utils.restart_failed_tasks(workflow) + return airflow_utils.restart_failed_tasks( + workflow.id, workflow.workflow_type + ) return airflow_utils.restart_workflow_dags( workflow.id, workflow.workflow_type, request.data.get("params") diff --git a/workflows/dags/author/author_create/author_create_approved.py b/workflows/dags/author/author_create/author_create_approved.py index 90dfc32c..12ff699b 100644 --- a/workflows/dags/author/author_create/author_create_approved.py +++ b/workflows/dags/author/author_create/author_create_approved.py @@ -106,6 +106,7 @@ def create_author_on_inspire(**context: dict) -> str: workflow_management_hook.partial_update_workflow( workflow_id=context["params"]["workflow_id"], workflow_partial_update_data={"data": workflow_data["data"]}, + collection=AUTHORS, ) return status