add build retries nixos option

This commit is contained in:
Jörg Thalheim 2024-07-09 11:16:40 +02:00 committed by mergify[bot]
parent d1d3746aa7
commit 701a5ac400
2 changed files with 16 additions and 2 deletions

View file

@ -240,8 +240,9 @@ class EvalErrorStep(steps.BuildStep):
class NixBuildCommand(buildstep.ShellMixin, steps.BuildStep): class NixBuildCommand(buildstep.ShellMixin, steps.BuildStep):
"""Builds a nix derivation.""" """Builds a nix derivation."""
def __init__(self, **kwargs: Any) -> None: def __init__(self, retries: int, **kwargs: Any) -> None:
kwargs = self.setupShellMixin(kwargs) kwargs = self.setupShellMixin(kwargs)
self.retries = retries
super().__init__(**kwargs) super().__init__(**kwargs)
@defer.inlineCallbacks @defer.inlineCallbacks
@ -253,7 +254,7 @@ class NixBuildCommand(buildstep.ShellMixin, steps.BuildStep):
res = cmd.results() res = cmd.results()
if res == util.FAILURE: if res == util.FAILURE:
retries = RETRY_COUNTER.retry_build(self.getProperty("build_uuid")) retries = RETRY_COUNTER.retry_build(self.getProperty("build_uuid"))
if retries > 0: if retries > self.retries - 1:
return util.RETRY return util.RETRY
return res return res
@ -446,6 +447,7 @@ def nix_build_config(
worker_names: list[str], worker_names: list[str],
cachix: CachixConfig | None = None, cachix: CachixConfig | None = None,
outputs_path: Path | None = None, outputs_path: Path | None = None,
retries: int = 1,
) -> BuilderConfig: ) -> BuilderConfig:
"""Builds one nix flake attribute.""" """Builds one nix flake attribute."""
factory = util.BuildFactory() factory = util.BuildFactory()
@ -472,6 +474,7 @@ def nix_build_config(
# 3 hours, defaults to 20 minutes # 3 hours, defaults to 20 minutes
# We increase this over the default since the build output might end up in a different `nix build`. # We increase this over the default since the build output might end up in a different `nix build`.
timeout=60 * 60 * 3, timeout=60 * 60 * 3,
retries=retries,
haltOnFailure=True, haltOnFailure=True,
), ),
) )
@ -571,6 +574,7 @@ def config_for_project(
eval_lock: MasterLock, eval_lock: MasterLock,
cachix: CachixConfig | None = None, cachix: CachixConfig | None = None,
outputs_path: Path | None = None, outputs_path: Path | None = None,
build_retries: int = 1,
) -> None: ) -> None:
config["projects"].append(Project(project.name)) config["projects"].append(Project(project.name))
config["schedulers"].extend( config["schedulers"].extend(
@ -644,6 +648,7 @@ def config_for_project(
worker_names, worker_names,
cachix=cachix, cachix=cachix,
outputs_path=outputs_path, outputs_path=outputs_path,
retries=build_retries,
), ),
nix_skipped_build_config(project, [SKIPPED_BUILDER_NAME]), nix_skipped_build_config(project, [SKIPPED_BUILDER_NAME]),
], ],
@ -788,6 +793,7 @@ class NixConfigurator(ConfiguratorBase):
# Shape of this file: [ { "name": "<worker-name>", "pass": "<worker-password>", "cores": "<cpu-cores>" } ] # Shape of this file: [ { "name": "<worker-name>", "pass": "<worker-password>", "cores": "<cpu-cores>" } ]
admins: list[str], admins: list[str],
auth_backend: str, auth_backend: str,
build_retries: int,
github: GithubConfig | None, github: GithubConfig | None,
gitea: GiteaConfig | None, gitea: GiteaConfig | None,
url: str, url: str,
@ -809,6 +815,7 @@ class NixConfigurator(ConfiguratorBase):
self.gitea = gitea self.gitea = gitea
self.url = url self.url = url
self.cachix = cachix self.cachix = cachix
self.build_retries = build_retries
if outputs_path is None: if outputs_path is None:
self.outputs_path = None self.outputs_path = None
else: else:
@ -861,6 +868,7 @@ class NixConfigurator(ConfiguratorBase):
eval_lock, eval_lock,
self.cachix, self.cachix,
self.outputs_path, self.outputs_path,
self.build_retries,
) )
config["workers"].append(worker.LocalWorker(SKIPPED_BUILDER_NAME)) config["workers"].append(worker.LocalWorker(SKIPPED_BUILDER_NAME))

View file

@ -75,6 +75,11 @@ in
Which OAuth2 backend to use. Which OAuth2 backend to use.
''; '';
}; };
buildRetries = lib.mkOption {
type = lib.types.ints.positive;
default = 1;
description = "Number of times a build is retried";
};
cachix = { cachix = {
name = lib.mkOption { name = lib.mkOption {
type = lib.types.nullOr lib.types.str; type = lib.types.nullOr lib.types.str;
@ -346,6 +351,7 @@ in
topic=${builtins.toJSON cfg.gitea.topic}, topic=${builtins.toJSON cfg.gitea.topic},
)" )"
}, },
build_retries=${builtins.toJSON cfg.buildRetries},
cachix=${ cachix=${
if cfg.cachix.name == null then if cfg.cachix.name == null then
"None" "None"