Skip to content
Prev Previous commit
Next Next commit
simplify select url logic
  • Loading branch information
sniper35 committed Feb 8, 2026
commit 1d93451354a218b391bc6ab3079e56d33681f84a
14 changes: 6 additions & 8 deletions miles/router/diffusion_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,12 @@ def _use_url(self):
"""Select worker URL with minimal active requests."""
if not self.worker_request_counts:
raise RuntimeError("No workers registered in the pool")
if not self.dead_workers:
url = min(self.worker_request_counts, key=self.worker_request_counts.get)
else:
valid_workers = (w for w in self.worker_request_counts if w not in self.dead_workers)
try:
url = min(valid_workers, key=self.worker_request_counts.get)
except ValueError:
raise RuntimeError("No healthy workers available in the pool") from None

valid_workers = (w for w in self.worker_request_counts if w not in self.dead_workers)
try:
url = min(valid_workers, key=self.worker_request_counts.get)
except ValueError:
raise RuntimeError("No healthy workers available in the pool") from None

self.worker_request_counts[url] += 1
return url
Expand Down