Skip to content

Commit

Permalink
added the mock callback for entry classification;
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjan-stha committed Dec 4, 2023
1 parent 673cc69 commit 4abc431
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
26 changes: 25 additions & 1 deletion analysis_module/mockserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,29 @@ def process_entry_extraction_mock(body) -> Any:
except Exception:
logger.error("Could not send data to callback url", exc_info=True)

def entry_classification_mock(body) -> Any:
process_entry_extraction_mock.apply_async(
args=(body,), countdown=2
) # Trigger task after 2 seconds
return json.dumps({"status": "Successfully received the request."}), 200

@shared_task
def process_entry_extraction_mock(body) -> Any:
callback_payload = MOCK_ENTRY_CLASSIFICATION
callback_payload.update({
"client_id": body["entries"][0]["client_id"]
})
callback_url = body["callback_url"]
try:
requests.post(
callback_url,
json=callback_payload,
timeout=30
)
logger.info("Successfully send data on callback url for entry classification")
except Exception:
logger.error("Could not send data to callback url", exc_info=True)


TYPE_ACTIONS_MOCK = {
"topicmodel": topicmodeling_mock_model,
Expand All @@ -370,7 +393,8 @@ def process_entry_extraction_mock(body) -> Any:
"ngrams": ngrams_mock_model,
"geolocation": geolocation_mock_model,
"text-extraction": text_extraction_mock,
"entry-extraction-classification": entry_extraction_mock
"entry-extraction-classification": entry_extraction_mock,
"entry-classification": entry_classification_mock
}


Expand Down
14 changes: 7 additions & 7 deletions analysis_module/views/predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from nlp_scripts.model_prediction.tags_mapping import AF2NLPMapping
from nlp_scripts.model_prediction.model_prediction import ModelTagsPrediction
from nlp_scripts.model_prediction.all_tags_mapping import get_vf_list
from analysis_module.mockserver import process_mock_request

import logging

Expand Down Expand Up @@ -63,12 +64,13 @@ def entry_classification(request: Request):
serializer.is_valid(raise_exception=True)

entries = serializer.validated_data["entries"]
req_type = NLPRequest.FeaturesType.ENTRY_CLASSIFICATION

if serializer.validated_data.get("mock") or IS_MOCKSERVER:
data = MOCK_ENTRY_CLASSIFICATION
data.update({
"client_id": entries[0]["client_id"]
})
return Response(data)
return process_mock_request(
request=serializer.validated_data,
request_type=req_type
)
if not entries:
return Response({})
# Create a NLPRequest object
Expand All @@ -79,8 +81,6 @@ def entry_classification(request: Request):
created_by=request.user,
)

req_type = NLPRequest.FeaturesType.ENTRY_CLASSIFICATION

resp = {
"type": req_type,
"message": "Request has been successfully queued.",
Expand Down

0 comments on commit 4abc431

Please sign in to comment.