Skip to content

Commit

Permalink
Merge pull request #119 from meedan/cv2-5589-timeouts-and-logs
Browse files Browse the repository at this point in the history
CV2-5589 add explicit timeout
  • Loading branch information
DGaffney authored Nov 14, 2024
2 parents 6bda299 + a12d92e commit 6e3d1db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/queue/processor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List
import json

from datetime import datetime
import requests

from lib import schemas
Expand Down Expand Up @@ -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}"
)
2 changes: 1 addition & 1 deletion test/lib/queue/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6e3d1db

Please sign in to comment.