From ddf9869f61554995e1a5fc8c5c7e5317ef20a333 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Wed, 18 Dec 2024 16:01:45 +0100 Subject: [PATCH] workflows: author submissions not erroring also some small config fixes for easy testing with docker * ref: https://github.com/cern-sis/issues-inspire/issues/643 --- Makefile | 1 + backend/inspirehep/config.py | 6 +++--- backend/inspirehep/submissions/views.py | 1 + .../author/author_create/author_create_init.py | 8 +++++++- .../hooks/backoffice/workflow_management_hook.py | 9 ++++++++- workflows/plugins/hooks/generic_http_hook.py | 6 ++++++ .../plugins/include/utils/set_workflow_status.py | 14 +++++++++----- 7 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 3e3eeb185..b976f6cd8 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ run: services start-inspirehep sleep setup-inspirehep start-backoffice sleep set run-inspirehep: services start-inspirehep sleep setup-inspirehep run-backoffice: services start-backoffice sleep setup-backoffice +start: services start-inspirehep start-backoffice start-inspirehep: echo -e "\033[0;32m Starting HEP. \033[0m" diff --git a/backend/inspirehep/config.py b/backend/inspirehep/config.py index bd2b11d3c..05ab0f117 100644 --- a/backend/inspirehep/config.py +++ b/backend/inspirehep/config.py @@ -31,7 +31,7 @@ FEATURE_FLAG_ENABLE_ORCID_PUSH = False FEATURE_FLAG_ENABLE_REDIRECTION_OF_PIDS = False FEATURE_FLAG_ENABLE_ASSIGN_AUTHOR_PAPERS = False -FEATURE_FLAG_ENABLE_SEND_TO_BACKOFFICE = False +FEATURE_FLAG_ENABLE_SEND_TO_BACKOFFICE = True # Only push to ORCIDs that match this regex. # Examples: # any ORCID -> ".*" @@ -51,8 +51,8 @@ INSPIRE_NEXT_URL = "http://localhost:5000" LEGACY_BASE_URL = "https://old.inspirehep.net" LEGACY_RECORD_URL_PATTERN = "http://inspirehep.net/record/{recid}" -INSPIRE_BACKOFFICE_URL = "https://backoffice.dev.inspirebeta.net" -AUTHENTICATION_TOKEN_BACKOFFICE = "CHANGE_ME" +INSPIRE_BACKOFFICE_URL = "http://host.docker.internal:8001" +AUTHENTICATION_TOKEN_BACKOFFICE = "2e04111a61e8f5ba6ecec52af21bbb9e81732085" MAX_API_RESULTS = 10000 REST_MIMETYPE_QUERY_ARG_NAME = "format" diff --git a/backend/inspirehep/submissions/views.py b/backend/inspirehep/submissions/views.py index ce1194e5e..b4506dcc7 100644 --- a/backend/inspirehep/submissions/views.py +++ b/backend/inspirehep/submissions/views.py @@ -89,6 +89,7 @@ def send_post_request_to_workflows( """ LOGGER.info("Sending post request to workflows", url=url, endpoint=endpoint) + LOGGER.info("YAHOO", url=url, endpoint=endpoint) headers = { "content-type": "application/json", "Authorization": f"{bearer_keyword} {token}", diff --git a/workflows/dags/author/author_create/author_create_init.py b/workflows/dags/author/author_create/author_create_init.py index 84c87baf5..cec929dcc 100644 --- a/workflows/dags/author/author_create/author_create_init.py +++ b/workflows/dags/author/author_create/author_create_init.py @@ -17,17 +17,22 @@ logger = logging.getLogger(__name__) +def task_failure_alert(context): + print(f"Task has failed, task_instance_key_str: {context['task_instance_key_str']}") + + @dag( params={ "workflow_id": Param(type="string", default=""), "data": Param(type="object", default={}), + "collection": Param(type="string", default=AUTHORS), }, start_date=datetime.datetime(2024, 5, 5), schedule=None, catchup=False, # TODO: what if callback fails? Data in backoffice not up to date! on_failure_callback=set_workflow_status_to_error, - tags=["authors"], + tags=[AUTHORS], ) def author_create_initialization_dag(): """ @@ -47,6 +52,7 @@ def author_create_initialization_dag(): @task() def set_workflow_status_to_running(**context): status_name = "running" + print(workflow_management_hook.headers) workflow_management_hook.set_workflow_status( status_name=status_name, workflow_id=context["params"]["workflow_id"] ) diff --git a/workflows/plugins/hooks/backoffice/workflow_management_hook.py b/workflows/plugins/hooks/backoffice/workflow_management_hook.py index 91e2395a5..c59715afe 100644 --- a/workflows/plugins/hooks/backoffice/workflow_management_hook.py +++ b/workflows/plugins/hooks/backoffice/workflow_management_hook.py @@ -19,6 +19,8 @@ class WorkflowManagementHook(BackofficeHook): def __init__(self, collection): super().__init__() self.endpoint = f"api/workflows/{collection}" + print("this is the endpoint") + print(self.endpoint) def set_workflow_status(self, status_name: str, workflow_id: str) -> Response: """ @@ -33,6 +35,8 @@ def set_workflow_status(self, status_name: str, workflow_id: str) -> Response: request_data = { "status": status_name, } + print("MY NAME IS JEFF") + print("setting up partial update") return self.partial_update_workflow( workflow_partial_update_data=request_data, workflow_id=workflow_id ) @@ -58,9 +62,12 @@ def partial_update_workflow( self, workflow_id: str, workflow_partial_update_data: dict ) -> Response: endpoint = f"{self.endpoint}/{workflow_id}/" + print("wow this is great") + print(self.headers) + print(workflow_partial_update_data) return self.run_with_advanced_retry( _retry_args=self.tenacity_retry_kwargs, method="PATCH", - data=workflow_partial_update_data, + json=workflow_partial_update_data, endpoint=endpoint, ) diff --git a/workflows/plugins/hooks/generic_http_hook.py b/workflows/plugins/hooks/generic_http_hook.py index c4ba29cc5..ae39a1e3e 100644 --- a/workflows/plugins/hooks/generic_http_hook.py +++ b/workflows/plugins/hooks/generic_http_hook.py @@ -51,6 +51,12 @@ def run( else: url = self.base_url + endpoint + print("wowawewa") + print(json) + print(data) + print(params) + print(headers) + req = requests.Request( method, url, json=json, data=data, params=params, headers=headers ) diff --git a/workflows/plugins/include/utils/set_workflow_status.py b/workflows/plugins/include/utils/set_workflow_status.py index 31a7c73b7..a6eeee8cb 100644 --- a/workflows/plugins/include/utils/set_workflow_status.py +++ b/workflows/plugins/include/utils/set_workflow_status.py @@ -1,6 +1,6 @@ import logging -from hooks.backoffice.workflow_management_hook import AUTHORS, WorkflowManagementHook +from hooks.backoffice.workflow_management_hook import WorkflowManagementHook from requests import Response logger = logging.getLogger(__name__) @@ -36,11 +36,15 @@ def set_workflow_status_to_error(context: dict) -> None: workflow_id (str): The identifier for the workflow. """ logger.info("Setting workflow status to error") - response = WorkflowManagementHook().set_workflow_status( - status_name="error", - workflow_id=context["params"]["workflow_id"], - collection=AUTHORS, + print("cossa") + print(context) + response = WorkflowManagementHook( + collection=context["params"]["collection"] + ).set_workflow_status( + status_name="error", workflow_id=context["params"]["workflow_id"] ) + print("response is") + print(response) try: response.raise_for_status() except Exception as e: