retry git clonning errors

This commit is contained in:
Jörg Thalheim 2023-12-03 11:48:01 +01:00 committed by mergify[bot]
parent b33d7e5a3e
commit 590f31eb6f

View file

@ -20,12 +20,13 @@ from buildbot.process.project import Project
from buildbot.process.properties import Interpolate, Properties from buildbot.process.properties import Interpolate, Properties
from buildbot.process.results import ALL_RESULTS, statusToString from buildbot.process.results import ALL_RESULTS, statusToString
from buildbot.steps.trigger import Trigger from buildbot.steps.trigger import Trigger
from buildbot.util import asyncSleep
from twisted.internet import defer, threads from twisted.internet import defer, threads
from twisted.python.failure import Failure from twisted.python.failure import Failure
from .github_projects import ( # noqa: E402 from .github_projects import (
GithubProject, GithubProject,
create_project_hook, create_project_hook, # noqa: E402
load_projects, load_projects,
refresh_projects, refresh_projects,
slugify_project_name, slugify_project_name,
@ -328,6 +329,25 @@ def reload_github_projects(
) )
# The builtin retry mechanism doesn't seem to work for github,
# since github is sometimes not delivering the pull request ref fast enough.
class GitWithRetry(steps.Git):
@defer.inlineCallbacks
def run_vc(
self, branch: str, revision: str, patch: str
) -> Generator[Any, object, Any]:
retry_counter = 0
while True:
try:
res = yield super().run_vc(branch, revision, patch)
return res
except Exception as e:
retry_counter += 1
if retry_counter == 3:
raise e
self.step_status.setText(f"Retrying git clone (error: {e})")
yield asyncSleep(2 << retry_counter) # 2, 4, 8
def nix_eval_config( def nix_eval_config(
project: GithubProject, project: GithubProject,
@ -348,7 +368,7 @@ def nix_eval_config(
f"https://git:%(secret:{github_token_secret})s@github.com/%(prop:project)s" f"https://git:%(secret:{github_token_secret})s@github.com/%(prop:project)s"
) )
factory.addStep( factory.addStep(
steps.Git( GitWithRetry(
repourl=url_with_secret, repourl=url_with_secret,
method="clean", method="clean",
submodules=True, submodules=True,
@ -690,8 +710,6 @@ class NixConfigurator(ConfiguratorBase):
self.url + "change_hook/github", self.url + "change_hook/github",
webhook_secret, webhook_secret,
) )
for project in projects:
config_for_project( config_for_project(
config, config,
project, project,