overlay_builders: address code-review nits on retry helpers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
13bd2e48f6
commit
6fc7f87943
2 changed files with 11 additions and 7 deletions
|
|
@ -10,11 +10,11 @@ from __future__ import annotations
|
|||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time as _time
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Callable, Protocol
|
||||
|
||||
import requests as _requests
|
||||
import requests
|
||||
from sqlalchemy import select
|
||||
|
||||
from l4d2host.paths import get_left4me_root
|
||||
|
|
@ -34,7 +34,8 @@ SCRIPT_SANDBOX_HELPER = "/usr/local/libexec/left4me/left4me-script-sandbox"
|
|||
DISK_BUDGET_BYTES = 20 * 1024**3
|
||||
|
||||
DOWNLOAD_RETRY_ATTEMPTS = 3
|
||||
DOWNLOAD_RETRY_BACKOFF_SECONDS = (1.0, 2.0, 4.0)
|
||||
DOWNLOAD_RETRY_BACKOFF_SECONDS = (1.0, 2.0)
|
||||
assert len(DOWNLOAD_RETRY_BACKOFF_SECONDS) == DOWNLOAD_RETRY_ATTEMPTS - 1
|
||||
|
||||
|
||||
def _sleep_with_cancel(
|
||||
|
|
@ -46,14 +47,14 @@ def _sleep_with_cancel(
|
|||
"""Sleep up to `seconds`, returning early (True) if `should_cancel` becomes
|
||||
True. Returns False on a full uninterrupted sleep. Polls every
|
||||
`poll_interval` seconds."""
|
||||
deadline = _time.monotonic() + seconds
|
||||
deadline = time.monotonic() + seconds
|
||||
while True:
|
||||
if should_cancel():
|
||||
return True
|
||||
remaining = deadline - _time.monotonic()
|
||||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
return False
|
||||
_time.sleep(min(poll_interval, remaining))
|
||||
time.sleep(min(poll_interval, remaining))
|
||||
|
||||
|
||||
def _download_with_retry(
|
||||
|
|
@ -73,7 +74,7 @@ def _download_with_retry(
|
|||
return
|
||||
except InterruptedError:
|
||||
raise
|
||||
except (_requests.RequestException, OSError) as exc:
|
||||
except (requests.RequestException, OSError) as exc:
|
||||
last_exc = exc
|
||||
if attempt == DOWNLOAD_RETRY_ATTEMPTS:
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -475,6 +475,9 @@ def test_download_with_retry_exhausts_and_raises(env, tmp_path, monkeypatch):
|
|||
meta, tmp_path / "cache",
|
||||
on_stderr=on_stderr, should_cancel=lambda: False,
|
||||
)
|
||||
# Two stderr "attempt N/3 failed" lines for attempts 1 and 2; the final
|
||||
# attempt re-raises without logging.
|
||||
assert sum(1 for line in err if "attempt" in line and "failed" in line) == 2
|
||||
|
||||
|
||||
def test_download_with_retry_propagates_interrupted(env, tmp_path, monkeypatch):
|
||||
|
|
|
|||
Loading…
Reference in a new issue