Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-5082 add logic to suppress a callback event to check-api when explicitly requested #440

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions app/main/controller/presto_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ def post(self, action, model_type):
if action == "add_item":
app.logger.info(f"Data looks like {data}")
result = similarity.callback_add_item(data.get("body"), model_type)
if data.get("body", {}).get("raw", {}).get("final_task") == "search":
result = similarity.callback_search_item(data.get("body"), model_type)
if result:
result["is_search_result_callback"] = True
callback_url = data.get("body", {}).get("raw", {}).get("callback_url", app.config['CHECK_API_HOST']) or app.config['CHECK_API_HOST']
if result and data.get("body", {}).get("raw", {}).get("requires_callback"):
app.logger.info(f"Sending callback to {callback_url} for {action} for model of {model_type} with body of {result}")
Webhook.return_webhook(callback_url, action, model_type, result)
output = {"action": action, "model_type": model_type, "data": result}
app.logger.info(f"PrestoResource value is {output}")
return_value = {"action": action, "model_type": model_type, "data": result}
if data.get("body", {}).get("raw", {}).get("suppress_response"):
# requested not to reply to caller with similarity response, so suppress it
return_value = {"action": action, "model_type": model_type, "data": result}
DGaffney marked this conversation as resolved.
Show resolved Hide resolved
else:
if data.get("body", {}).get("raw", {}).get("final_task") == "search":
DGaffney marked this conversation as resolved.
Show resolved Hide resolved
# compute a set of items that are similar to the just-stored item and respond to caller with them
result = similarity.callback_search_item(data.get("body"), model_type)
if result:
result["is_search_result_callback"] = True
callback_url = data.get("body", {}).get("raw", {}).get("callback_url", app.config['CHECK_API_HOST']) or app.config['CHECK_API_HOST']
if result and data.get("body", {}).get("raw", {}).get("requires_callback"):
app.logger.info(f"Sending callback to {callback_url} for {action} for model of {model_type} with body of {result}")
Webhook.return_webhook(callback_url, action, model_type, result)
return_value = {"action": action, "model_type": model_type, "data": result}
DGaffney marked this conversation as resolved.
Show resolved Hide resolved
app.logger.info(f"PrestoResource value is {return_value}")
r = redis_client.get_client()
r.lpush(f"{model_type}_{item_id}", json.dumps(data))
r.expire(f"{model_type}_{item_id}", 60*60*24)
Expand Down
1 change: 1 addition & 0 deletions app/main/controller/similarity_async_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def post(self, similarity_type):
else:
package = similarity.get_body_for_media_document(args, 'query')
#Default to true for this endpoint instead of false in most other cases
package["suppress_response"] = args.get("suppress_response", False)
package["requires_callback"] = args.get("requires_callback", True)
response, waiting_for_callback = similarity.async_get_similar_items(package, similarity_type)
if not waiting_for_callback:
Expand Down
Loading