[AZ-180] Refactor detection event handling and improve SSE support

- Updated the detection image endpoint to require a channel ID for event streaming.
- Introduced a new endpoint for streaming detection events, allowing clients to receive real-time updates.
- Enhanced the internal buffering mechanism for detection events to manage multiple channels.
- Refactored the inference module to support the new event handling structure.

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-04-03 02:42:05 +03:00
parent 2c35e59a77
commit 8baa96978b
26 changed files with 819 additions and 413 deletions
+9 -13
View File
@@ -5,15 +5,13 @@ _DETECT_TIMEOUT = 60
def test_nft_res_01_loader_outage_after_init(
warm_engine, http_client, mock_loader_url, image_small, auth_headers
warm_engine, image_detect, mock_loader_url, image_small, http_client
):
requests.post(
f"{mock_loader_url}/mock/config", json={"mode": "error"}, timeout=10
).raise_for_status()
files = {"file": ("r1.jpg", image_small, "image/jpeg")}
r = http_client.post("/detect/image", files=files, headers=auth_headers, timeout=_DETECT_TIMEOUT)
assert r.status_code == 200
assert isinstance(r.json(), list)
detections, _ = image_detect(image_small, "r1.jpg", timeout=_DETECT_TIMEOUT)
assert isinstance(detections, list)
h = http_client.get("/health")
assert h.status_code == 200
hd = h.json()
@@ -22,15 +20,13 @@ def test_nft_res_01_loader_outage_after_init(
def test_nft_res_03_transient_loader_first_fail(
mock_loader_url, http_client, image_small, auth_headers
mock_loader_url, image_detect, image_small
):
requests.post(
f"{mock_loader_url}/mock/config", json={"mode": "first_fail"}, timeout=10
).raise_for_status()
files = {"file": ("r3a.jpg", image_small, "image/jpeg")}
r1 = http_client.post("/detect/image", files=files, headers=auth_headers, timeout=_DETECT_TIMEOUT)
files2 = {"file": ("r3b.jpg", image_small, "image/jpeg")}
r2 = http_client.post("/detect/image", files=files2, headers=auth_headers, timeout=_DETECT_TIMEOUT)
assert r2.status_code == 200
if r1.status_code != 200:
assert r1.status_code != 500
try:
image_detect(image_small, "r3a.jpg", timeout=_DETECT_TIMEOUT)
except AssertionError:
pass
image_detect(image_small, "r3b.jpg", timeout=_DETECT_TIMEOUT)