Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable retries for server errors in calls to /missing_objects #136

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions flat-manager-client
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,30 @@ def chunks(iterable, n):
retry=TENACITY_RETRY_EXCEPTIONS,
reraise=True,
)
async def _missing_chunk(session, build_url, chunk, headers):
wanted_json = json.dumps({"wanted": chunk}).encode("utf-8")
data = gzip.compress(wanted_json)

resp = await session.get(build_url + "/missing_objects", data=data, headers=headers)
async with resp:
if resp.status >= 500:
raise ServerApiError(resp, await resp.text())
if resp.status != 200:
raise ApiError(resp, await resp.text())

return await resp.json()


async def missing_objects(session, build_url, token, wanted):
missing = []
for chunk in chunks(wanted, 2000):
wanted_json = json.dumps({"wanted": chunk}).encode("utf-8")
data = gzip.compress(wanted_json)
headers = {
"Authorization": "Bearer " + token,
"Content-Encoding": "gzip",
"Content-Type": "application/json",
}
resp = await session.get(
build_url + "/missing_objects", data=data, headers=headers
)
async with resp:
if resp.status != 200:
raise ApiError(resp, await resp.text())
data = await resp.json()
missing.extend(data["missing"])
data = await _missing_chunk(session, build_url, chunk, headers)
missing.extend(data["missing"])
return missing


Expand Down
Loading