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-5589 add explicit timeout #119

Merged
merged 2 commits into from
Nov 14, 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
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
Loading