Skip to content

Commit 958ca62

Browse files
timeout
1 parent a5618a8 commit 958ca62

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

pioreactorui/api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def get_all_workers() -> list[str]:
7777
return list(r["unit"] for r in result)
7878

7979

80-
def broadcast_get_across_cluster(endpoint: str) -> dict[str, Any]:
80+
def broadcast_get_across_cluster(endpoint: str, timeout: float = 1.0) -> dict[str, Any]:
8181
assert endpoint.startswith("/unit_api")
82-
return tasks.multicast_get_across_cluster(endpoint, get_all_workers())
82+
return tasks.multicast_get_across_cluster(endpoint, get_all_workers(), timeout=timeout)
8383

8484

8585
def broadcast_post_across_cluster(endpoint: str, json: dict | None = None) -> Result:
@@ -776,9 +776,11 @@ def remove_calibration(pioreactor_unit, cal_type, cal_name) -> ResponseReturnVal
776776
@api.route("/units/<pioreactor_unit>/plugins/installed", methods=["GET"])
777777
def get_plugins_on_machine(pioreactor_unit: str) -> ResponseReturnValue:
778778
if pioreactor_unit == UNIVERSAL_IDENTIFIER:
779-
task = broadcast_get_across_cluster("/unit_api/plugins/installed")
779+
task = broadcast_get_across_cluster("/unit_api/plugins/installed", timeout=5)
780780
else:
781-
task = tasks.multicast_get_across_cluster("/unit_api/plugins/installed", [pioreactor_unit])
781+
task = tasks.multicast_get_across_cluster(
782+
"/unit_api/plugins/installed", [pioreactor_unit], timeout=5
783+
)
782784

783785
return create_task_response(task)
784786

pioreactorui/tasks.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,11 @@ def multicast_post_across_cluster(
309309

310310

311311
@huey.task()
312-
def get_worker(worker: str, endpoint: str, json: dict | None = None) -> tuple[str, Any]:
312+
def get_worker(
313+
worker: str, endpoint: str, json: dict | None = None, timeout=1.0
314+
) -> tuple[str, Any]:
313315
try:
314-
r = get_from(resolve_to_address(worker), endpoint, json=json, timeout=1)
316+
r = get_from(resolve_to_address(worker), endpoint, json=json, timeout=timeout)
315317
r.raise_for_status()
316318
return worker, r.json()
317319
except HTTPException:
@@ -321,12 +323,12 @@ def get_worker(worker: str, endpoint: str, json: dict | None = None) -> tuple[st
321323

322324
@huey.task()
323325
def multicast_get_across_cluster(
324-
endpoint: str, workers: list[str], json: dict | None = None
326+
endpoint: str, workers: list[str], json: dict | None = None, timeout: float = 1.0
325327
) -> dict[str, Any]:
326328
# this function "consumes" one huey thread waiting fyi
327329
assert endpoint.startswith("/unit_api")
328330

329-
tasks = get_worker.map(((worker, endpoint, json) for worker in workers))
331+
tasks = get_worker.map(((worker, endpoint, json, timeout) for worker in workers))
330332

331333
return {worker: response for (worker, response) in tasks.get(blocking=True)}
332334

0 commit comments

Comments
 (0)