From e78943c18d541eef84a7a88296ac6ad6cf4fdbf3 Mon Sep 17 00:00:00 2001 From: Devin Gaffney Date: Wed, 13 Nov 2024 11:17:43 -0800 Subject: [PATCH 1/2] CV2-5589 add explicit timeout --- lib/queue/processor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/queue/processor.py b/lib/queue/processor.py index a891baf3..fdde2666 100644 --- a/lib/queue/processor.py +++ b/lib/queue/processor.py @@ -1,6 +1,6 @@ from typing import List import json - +from datetime import datetime import requests from lib import schemas @@ -60,15 +60,17 @@ def send_callback(self, message): try: schemas.parse_output_message(message) # will raise exceptions if not valid, e.g. too large of a message callback_url = message.get("body", {}).get("callback_url") + start_time = datetime.now() response = requests.post( callback_url, + timeout=30, json=message, # headers={"Content-Type": "application/json"}, ) - # check for error with the callback if response.ok != True: logger.error(f"Callback error responding to {callback_url} :{response}") except Exception as e: + duration = (datetime.now() - start_time).total_seconds() logger.error( - f"Callback fail! Failed with {e} on {callback_url} with message of {message}" + f"Callback fail! Failed with {e} on {callback_url} with message of {message}, duration was {duration}" ) From a12d92e3bed7affb229cf2ebc36fd4817ced5b18 Mon Sep 17 00:00:00 2001 From: Devin Gaffney Date: Wed, 13 Nov 2024 11:30:21 -0800 Subject: [PATCH 2/2] fix test --- test/lib/queue/test_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/queue/test_processor.py b/test/lib/queue/test_processor.py index c6b5a24d..5748cf12 100644 --- a/test/lib/queue/test_processor.py +++ b/test/lib/queue/test_processor.py @@ -40,7 +40,7 @@ def test_send_callbacks(self): def test_send_callback(self, mock_post): message_body = {"body": {"callback_url": "http://example.com", "text": "This is a test", "id": 123, "result": {"hash_value": [1,2,3]}}, "model_name": "mean_tokens__Model"} self.queue_processor.send_callback(message_body) - mock_post.assert_called_once_with("http://example.com", json=message_body) + mock_post.assert_called_once_with("http://example.com", timeout=30, json=message_body) @patch('lib.queue.processor.requests.post') def test_send_callback_failure(self, mock_post):