Skip to content

Commit

Permalink
Handle unpredictable GitHub timeouts (#31)
Browse files Browse the repository at this point in the history
* Handle unpredictable GitHub timeouts.

* Use for instead of while.

---------

Co-authored-by: stephenworsley <[email protected]>
  • Loading branch information
trexfeathers and stephenworsley authored Dec 5, 2024
1 parent d5a4892 commit 7e3e8d1
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions peloton/update_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,29 @@ def _run_sub_mutation(self, page_slice: slice) -> list:
mutation = sgqlc.operation.Operation(github_schema_root.mutation_type)
for ix in self._indexes[page_slice]:
self._add_selector(mutation=mutation, index=ix)
result = run_operation(mutation)
# Fields are accessed from mutation results via their keys.
payloads = [result[a] for a in self._aliases[page_slice]]
return payloads

# Handle unpredictable GitHub timeouts.
result = None
exception = None
for attempts in range(5):
try:
result = run_operation(mutation)
break
except Exception as exc:
exception = exc

sleep(5)

if result is not None:
# Fields are accessed from mutation results via their keys.
payloads = [result[a] for a in self._aliases[page_slice]]
return payloads
elif exception is not None:
raise exception
else:
message = "Unexpected: mutation returned no result and no exception."
raise RuntimeError(message)


def _get_data_from_sub_mutations(self, payloads: list[list]) -> list | None:
"""
Expand Down

0 comments on commit 7e3e8d1

Please sign in to comment.