Skip to content

Commit 99a4667

Browse files
committed
UPDATED sender
1 parent a9e4d8c commit 99a4667

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/Core/utils.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,25 @@ def sender(operation, data, cstm_port=None):
1818
if operation == "add_camera":
1919
url = "/cameras"
2020
port = 3010
21-
if operation == "run":
21+
elif operation == "run":
2222
url = "/run"
2323
port = 3333
24-
25-
if operation == "stop":
24+
elif operation == "stop":
2625
url = "/stop"
2726
port = 3333
28-
29-
if operation == "search":
27+
elif operation == "search":
3028
url = f"/image/search?image_name={data}"
3129
port = 3333
32-
33-
if operation == "loading":
30+
elif operation == "loading":
3431
url = f"/image/download?image_name={data}"
3532
port = 3333
36-
33+
else:
34+
logger.error(f"Unknown operation: {operation}")
35+
return {"error": "Unknown operation"}
3736

3837
if ALGORITHMS_CONTROLLER_SERVICE_URL and port == 3333:
3938
service_url = ALGORITHMS_CONTROLLER_SERVICE_URL
4039

41-
4240
if ONVIF_SERVICE_URL and port == 3010:
4341
service_url = ONVIF_SERVICE_URL
4442

@@ -47,15 +45,21 @@ def sender(operation, data, cstm_port=None):
4745
else:
4846
link = f"{service_url}:{port}{url}"
4947

50-
if operation in ["search", "loading"]:
51-
request = requests.get(f"{service_url}:{port}{url}")
52-
logger.warning(f"Request status from sender docker_image -> {request}")
53-
else:
54-
request = requests.post(link, json=data)
55-
logger.warning(f"request status from sender -> {request}")
48+
logger.warning(f"Sending request to {link} with data {data}")
49+
50+
try:
51+
if operation in ["search", "loading"]:
52+
request = requests.get(link)
53+
else:
54+
request = requests.post(link, json=data)
55+
56+
logger.warning(f"Request status from sender -> {request.status_code}")
5657
request.raise_for_status()
5758

58-
result = request.json()
59-
logger.warning(f"result from sender -> {result}")
59+
result = request.json()
60+
logger.warning(f"Result from sender -> {result}")
61+
return result
6062

61-
return result
63+
except requests.exceptions.RequestException as e:
64+
logger.error(f"Request failed: {e}")
65+
return {"error": str(e)}

0 commit comments

Comments
 (0)