Skip to content

Commit

Permalink
client: cumulative timeout for download
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Jun 16, 2021
1 parent 42b7dc6 commit 72ceb48
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mpcontribs-client/mpcontribs/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ def download_contributions(
Returns:
Number of new downloads written to disk.
"""
start = time.perf_counter()
query = query or {}
include = include or []
outdir = Path(outdir) or Path(".")
Expand All @@ -1304,6 +1305,11 @@ def download_contributions(
ndownloads = 0

for name, values in all_ids.items():
timeout -= time.perf_counter() - start
if timeout < 1:
return ndownloads

start = time.perf_counter()
cids = list(values["ids"])
paths, per_page = self._download_resource(
resource="contributions", ids=cids,
Expand All @@ -1318,6 +1324,11 @@ def download_contributions(
print(f"No new contributions to download for '{name}'.")

for component in components:
timeout -= time.perf_counter() - start
if timeout < 1:
return ndownloads

start = time.perf_counter()
ids = list(values[component]["ids"])
paths, per_page = self._download_resource(
resource=component, ids=ids,
Expand Down

0 comments on commit 72ceb48

Please sign in to comment.