Skip to content

Commit

Permalink
CV2-5082 add logic to suppress a callback event to check-api when exp…
Browse files Browse the repository at this point in the history
…licitly requested (#440)

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

* Update app/main/controller/presto_controller.py

Co-authored-by: Skye Bender-deMoll <[email protected]>

* Update app/main/controller/presto_controller.py

Co-authored-by: Skye Bender-deMoll <[email protected]>

* Small tweak

---------

Co-authored-by: Skye Bender-deMoll <[email protected]>
  • Loading branch information
DGaffney and skyemeedan authored Aug 27, 2024
1 parent 7033212 commit 5413a6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
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}
else:
if data.get("body", {}).get("raw", {}).get("final_task") == "search":
# 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}
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

0 comments on commit 5413a6e

Please sign in to comment.