fix: advertise retry delay on context timeout (#40)
This commit is contained in:
parent
9ea8667264
commit
965b24a183
|
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import math
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
|
@ -75,7 +76,9 @@ async def context() -> JSONResponse:
|
|||
{"panel": "gitea", "action": "set GITEA_URL + GITEA_TOKEN", "target": "/root/stackchain-dashboard/.env or systemd env", "priority": "high"},
|
||||
],
|
||||
"error": error_message,
|
||||
})
|
||||
}, headers={
|
||||
"Retry-After": str(max(1, math.ceil(CONTEXT_TIMEOUT_SECONDS)))
|
||||
} if isinstance(e, TimeoutError) else None)
|
||||
user_model = User(id=user_data["id"], login=user_data["login"], full_name=user_data.get("full_name", ""), email=user_data.get("email", ""))
|
||||
repo_models = [
|
||||
Repo(id=r["id"], name=r["name"], full_name=r["full_name"], description=r.get("description", ""), url=r["html_url"], updated_at=r.get("updated_at", ""))
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ async def test_context_returns_fallback_when_gitea_exceeds_deadline(monkeypatch)
|
|||
response = await main.context()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["retry-after"] == "1"
|
||||
assert b'"repos":[]' in response.body
|
||||
assert b'"error":"Gitea context request timed out after 0.01s"' in response.body
|
||||
assert cancelled.is_set()
|
||||
Loading…
Reference in New Issue
Block a user