Skip to content

Commit

Permalink
workflows: author submissions not erroring
Browse files Browse the repository at this point in the history
also some small config fixes for easy testing with docker

* ref: cern-sis/issues-inspire#643
  • Loading branch information
DonHaul committed Dec 18, 2024
1 parent 3942899 commit ddf9869
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions backend/inspirehep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> ".*"
Expand All @@ -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"

Expand Down
1 change: 1 addition & 0 deletions backend/inspirehep/submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
8 changes: 7 additions & 1 deletion workflows/dags/author/author_create/author_create_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand All @@ -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"]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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
)
Expand All @@ -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,
)
6 changes: 6 additions & 0 deletions workflows/plugins/hooks/generic_http_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
14 changes: 9 additions & 5 deletions workflows/plugins/include/utils/set_workflow_status.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ddf9869

Please sign in to comment.