From e846e00dcfade000c1c0f6daf16ba3c137a7068a Mon Sep 17 00:00:00 2001 From: Ranjan Shrestha Date: Wed, 26 Jun 2024 11:00:46 +0545 Subject: [PATCH] data sent in key-value pairs to maintain a single url link in callback payload; --- analysis_module/mockserver.py | 27 ++++++++++------------- analysis_module/utils.py | 41 ----------------------------------- 2 files changed, 11 insertions(+), 57 deletions(-) diff --git a/analysis_module/mockserver.py b/analysis_module/mockserver.py index d474293..8c8f402 100644 --- a/analysis_module/mockserver.py +++ b/analysis_module/mockserver.py @@ -17,7 +17,7 @@ from core.models import NLPRequest from core_server.settings import ENDPOINT_NAME from .mock_templates import MOCK_ENTRY_CLASSIFICATION, MOCK_ENTRY_CLASSIFICATION_FORMATTED, MOCK_GEOLOCATION # noqa -from .utils import send_callback_url_request, send_callback_url_request_for_summarization +from .utils import send_callback_url_request logger = logging.getLogger("__name__") @@ -138,32 +138,27 @@ def process_summarization(body: dict) -> Any: send_callback_url_request_for_summarization( callback_url=callback_url, client_id=client_id, - summary_filepath="", - analytical_statement_filepath="", - info_gaps_filepath="", + filepath="", status=NLPRequest.RequestStatus.PROCESS_INPUT_URL_FAILED, ) return summary_data = " ".join(["This is a fake response.\n"] + excerpts) - summary_filepath = save_data_local_and_get_url( - dir_name="summarization", client_id=client_id, data=summary_data - ) analytical_statement_data = " ".join(["This is autogenerated Analytical Statement.\n"] + excerpts) - analytical_statement_filepath = save_data_local_and_get_url( - dir_name="analytical_statement", client_id=client_id, data=analytical_statement_data - ) info_gaps_data = " ".join(["This is autogenerated info gaps.\n"] + excerpts) - info_gaps_filepath = save_data_local_and_get_url( - dir_name="info_gaps", client_id=client_id, data=info_gaps_data + data = { + "summary": summary_data, + "analytical_statement": analytical_statement_data, + "info_gaps": info_gaps_data + } + filepath = save_data_local_and_get_url( + dir_name="summarization", client_id=client_id, data=data ) - send_callback_url_request_for_summarization( + send_callback_url_request( callback_url=callback_url, client_id=client_id, - summary_filepath=summary_filepath, - analytical_statement_filepath=analytical_statement_filepath, - info_gaps_filepath=info_gaps_filepath, + filepath=filepath, status=NLPRequest.RequestStatus.SUCCESS, ) diff --git a/analysis_module/utils.py b/analysis_module/utils.py index 64c2f34..5b4c564 100644 --- a/analysis_module/utils.py +++ b/analysis_module/utils.py @@ -161,47 +161,6 @@ def send_callback_url_request(callback_url: str, client_id: str, filepath: str, logging.error("No callback url found.") return json.dumps({"status": "No callback url found."}), 400 -@shared_task -def send_callback_url_request_for_summarization( - callback_url: str, - client_id: str, - summary_filepath: str, - analytical_statement_filepath: str, - info_gaps_filepath: str, - status: int -) -> Any: - """send callback url""" - - time.sleep(1) - if callback_url: - response_callback_url = requests.post( - callback_url, - json={ - "client_id": client_id, - "summary_url": summary_filepath, - "analytical_statement_url": analytical_statement_filepath, - "info_gaps_url": info_gaps_filepath, - "status": status, - }, - timeout=30, - ) - if response_callback_url.status_code == 200: - logging.info("Request sent successfully.") - return json.dumps({"status": "Request sent successfully."}) - else: - logging.info( - f"Some errors occurred. StatusCode: {response_callback_url.status_code}" - ) - return json.dumps( - { - "status": f"Error occurred with statuscode: {response_callback_url.status_code}" - } - ) - - logging.error("No callback url found.") - return json.dumps({"status": "No callback url found."}), 400 - - def get_geolocations(excerpts: List[str], req_timeout: int = 60): """ Get geolocations from excerpts by requesting from geolocation module """ if not GEOLOCATION_ECS_ENDPOINT: