refactor: extract _dispatch_post to remove duplicate retry logic
This commit is contained in:
+16
-22
@@ -287,6 +287,20 @@ def sanitize_client_resolution(width: Optional[int], height: Optional[int]) -> t
|
||||
return clamped_width, clamped_height
|
||||
|
||||
|
||||
def _dispatch_post(url: str, payload: dict) -> None:
|
||||
last_exc = None
|
||||
for _ in range(max(1, POOL_DISPATCH_RETRIES)):
|
||||
try:
|
||||
resp = requests.post(url, json=payload, timeout=POOL_DISPATCH_REQUEST_TIMEOUT_SECONDS)
|
||||
resp.raise_for_status()
|
||||
return
|
||||
except Exception as exc:
|
||||
last_exc = exc
|
||||
time.sleep(max(0.0, POOL_DISPATCH_SLEEP_SECONDS))
|
||||
if last_exc:
|
||||
raise last_exc
|
||||
|
||||
|
||||
def dispatch_universal_target(slot: int, service: Service, width: Optional[int] = None, height: Optional[int] = None) -> None:
|
||||
name = universal_container_name(slot)
|
||||
url = ""
|
||||
@@ -312,17 +326,7 @@ def dispatch_universal_target(slot: int, service: Service, width: Optional[int]
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="Universal pool supports WEB/RDP only")
|
||||
|
||||
last_exc = None
|
||||
for _ in range(max(1, POOL_DISPATCH_RETRIES)):
|
||||
try:
|
||||
resp = requests.post(url, json=payload, timeout=POOL_DISPATCH_REQUEST_TIMEOUT_SECONDS)
|
||||
resp.raise_for_status()
|
||||
return
|
||||
except Exception as exc:
|
||||
last_exc = exc
|
||||
time.sleep(max(0.0, POOL_DISPATCH_SLEEP_SECONDS))
|
||||
if last_exc:
|
||||
raise last_exc
|
||||
_dispatch_post(url, payload)
|
||||
|
||||
|
||||
def dispatch_web_pool_target(slot: int, service: Service, width: Optional[int] = None, height: Optional[int] = None) -> None:
|
||||
@@ -334,17 +338,7 @@ def dispatch_web_pool_target(slot: int, service: Service, width: Optional[int] =
|
||||
if width and height:
|
||||
payload["width"] = width
|
||||
payload["height"] = height
|
||||
last_exc = None
|
||||
for _ in range(max(1, POOL_DISPATCH_RETRIES)):
|
||||
try:
|
||||
resp = requests.post(url, json=payload, timeout=POOL_DISPATCH_REQUEST_TIMEOUT_SECONDS)
|
||||
resp.raise_for_status()
|
||||
return
|
||||
except Exception as exc:
|
||||
last_exc = exc
|
||||
time.sleep(max(0.0, POOL_DISPATCH_SLEEP_SECONDS))
|
||||
if last_exc:
|
||||
raise last_exc
|
||||
_dispatch_post(url, payload)
|
||||
|
||||
|
||||
def create_runtime_container(service: Service, session_id: str):
|
||||
|
||||
Reference in New Issue
Block a user