mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 22:15:10 +00:00
fix: docsgpt up review follow-ups
- wait_healthy starts no request once the deadline is reached, and neither its pauses nor the requests after the first run past it; the first attempt still always runs (status uses a zero timeout). - envfile writes $ as $$ inside double quotes, which Compose interpolates, and reads $$ back as $, so a value such as pa$w'rd reaches the container unchanged. - Upgrading no longer describes the working directory as the data home.
This commit is contained in:
1 parent
5e699b0168
commit
f6bf4fefd1
5 files changed
+64
-10
No files matched your search
@@ -125,18 +125,28 @@ def wait_healthy(
|
||||
sleep: Callable[[float], None] = time.sleep,
|
||||
clock: Callable[[], float] = time.monotonic,
|
||||
) -> bool:
|
||||
"""Poll ``url`` until it answers 2xx (True) or ``timeout`` seconds pass (False); tries at least once."""
|
||||
"""Poll ``url`` until it answers 2xx (True) or ``timeout`` seconds pass (False); tries at least once.
|
||||
|
||||
No request starts once the deadline is reached, and neither the pauses nor the
|
||||
requests after the first run past it.
|
||||
"""
|
||||
deadline = clock() + timeout
|
||||
request_timeout = min(5.0, timeout) if timeout > 0 else 5.0
|
||||
while True:
|
||||
try:
|
||||
with opener(url, timeout=5) as response:
|
||||
with opener(url, timeout=request_timeout) as response:
|
||||
if 200 <= response.status < 300:
|
||||
return True
|
||||
except (OSError, http.client.HTTPException):
|
||||
pass
|
||||
if clock() >= deadline:
|
||||
remaining = deadline - clock()
|
||||
if remaining <= 0:
|
||||
return False
|
||||
sleep(2)
|
||||
sleep(min(2.0, remaining))
|
||||
remaining = deadline - clock()
|
||||
if remaining <= 0:
|
||||
return False
|
||||
request_timeout = min(5.0, remaining)
|
||||
|
||||
|
||||
def lan_ip() -> str:
|
||||
|
||||
@@ -19,19 +19,21 @@ def _parse_value(raw: str) -> str:
|
||||
if len(value) >= 2 and value[0] == value[-1] == "'":
|
||||
return value[1:-1]
|
||||
if len(value) >= 2 and value[0] == value[-1] == '"':
|
||||
return re.sub(r'\\(["\\])', r"\1", value[1:-1])
|
||||
return re.sub(r'\\(["\\])', r"\1", value[1:-1]).replace("$$", "$")
|
||||
return value.split(" #", 1)[0].rstrip()
|
||||
|
||||
|
||||
def _format_value(value: str) -> str:
|
||||
"""``value`` quoted so it reads back unchanged."""
|
||||
"""``value`` quoted so it reads back unchanged, and so Compose passes it on unchanged."""
|
||||
if "\n" in value or "\r" in value:
|
||||
raise ValueError("a .env value cannot contain a newline")
|
||||
if _PLAIN.match(value):
|
||||
return value
|
||||
if "'" not in value:
|
||||
# Compose does not interpolate single-quoted values.
|
||||
return f"'{value}'"
|
||||
return '"' + value.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
||||
# Double quotes are interpolated: $$ is Compose's literal dollar.
|
||||
return '"' + value.replace("\\", "\\\\").replace('"', '\\"').replace("$", "$$") + '"'
|
||||
|
||||
|
||||
def read(path: Path) -> dict[str, str]:
|
||||
|
||||
Reference in new issue
Block a user