Skip to content

Commit

Permalink
data sent in key-value pairs to maintain a single url link in callbac…
Browse files Browse the repository at this point in the history
…k payload;
  • Loading branch information
ranjan-stha committed Jun 26, 2024
1 parent bcfad31 commit e846e00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 57 deletions.
27 changes: 11 additions & 16 deletions analysis_module/mockserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__")
Expand Down Expand Up @@ -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,
)

Expand Down
41 changes: 0 additions & 41 deletions analysis_module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e846e00

Please sign in to comment.