Skip to content

Commit

Permalink
Another backoff for cruft (#207)
Browse files Browse the repository at this point in the history
* Add retry with backoff also for clone

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
grst and pre-commit-ci[bot] committed Jun 6, 2023
1 parent e03a54d commit 03ef73a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions scripts/src/scverse_template_scripts/cruft_prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import typer
from furl import furl
from git.exc import GitCommandError
from git.repo import Repo
from git.util import Actor
from github import ContentFile, Github, UnknownObjectException
Expand Down Expand Up @@ -142,8 +143,16 @@ def run_cruft(cwd: Path) -> CompletedProcess:
return run(args, check=True, cwd=cwd)


# GitHub says that up to 5 minutes of wait are OK,
# So we error our once we wait longer, i.e. when 2ⁿ = 5 min × 60 sec/min
n_retries = math.ceil(math.log(5 * 60) / math.log(2)) # = ⌈~8.22⌉ = 9
# Due to exponential backoff, we’ll maximally wait 2⁹ sec, or 8.5 min


def cruft_update(con: GitHubConnection, repo: GHRepo, path: Path, pr: PR) -> bool:
clone = Repo.clone_from(con.auth(repo.clone_url), path)
clone = retry_with_backoff(
lambda: Repo.clone_from(con.auth(repo.clone_url), path), retries=n_retries, exc_cls=GitCommandError
)
branch = clone.create_head(pr.branch, clone.active_branch)
branch.checkout()

Expand All @@ -166,12 +175,6 @@ def cruft_update(con: GitHubConnection, repo: GHRepo, path: Path, pr: PR) -> boo
return True


# GitHub says that up to 5 minutes of wait are OK,
# So we error our once we wait longer, i.e. when 2ⁿ = 5 min × 60 sec/min
n_retries = math.ceil(math.log(5 * 60) / math.log(2)) # = ⌈~8.22⌉ = 9
# Due to exponential backoff, we’ll maximally wait 2⁹ sec, or 8.5 min


def get_fork(con: GitHubConnection, repo: GHRepo) -> GHRepo:
if fork := next((f for f in repo.get_forks() if f.owner.id == con.user.id), None):
return fork
Expand Down

0 comments on commit 03ef73a

Please sign in to comment.