nix: Fix deployment parallelization

This commit is contained in:
Zhaofeng Li 2021-12-02 23:49:35 -08:00
parent 5b2d8d75e7
commit 2bba64a002
4 changed files with 48 additions and 1 deletions

View file

@ -0,0 +1,18 @@
let
tools = import ../tools.nix {};
in tools.makeTest {
name = "colmena-apply-fail";
bundle = ./.;
testScript = ''
beta.block()
# HACK: copy stderr to both stdout and stderr
# (stdout is what's returned, and only stderr appears on screen during the build)
logs = deployer.fail("cd /tmp/bundle && ${tools.colmenaExec} apply -v --eval-node-limit 4 --on @target 2> >(tee /dev/stderr)")
alpha.succeed("grep SUCCESS /etc/deployment")
gamma.succeed("grep SUCCESS /etc/deployment")
'';
}

View file

@ -0,0 +1,23 @@
let
tools = import ./tools.nix { insideVm = true; };
testPkg = let
text = builtins.trace "must appear during evaluation" ''
echo "must appear during build"
mkdir -p $out
'';
in tools.pkgs.runCommand "test-package" {} text;
in {
meta = {
nixpkgs = tools.pkgs;
};
defaults = {
environment.etc."deployment".text = "SUCCESS";
};
deployer = tools.getStandaloneConfigFor "deployer";
alpha = tools.getStandaloneConfigFor "alpha";
beta = tools.getStandaloneConfigFor "beta";
gamma = tools.getStandaloneConfigFor "gamma";
}

View file

@ -1,5 +1,6 @@
{ {
apply = import ./apply; apply = import ./apply;
apply-fail = import ./apply-fail;
apply-local = import ./apply-local; apply-local = import ./apply-local;
exec = import ./exec; exec = import ./exec;
} }

View file

@ -226,11 +226,16 @@ impl Deployment {
return Ok(()); return Ok(());
} }
let mut futures = Vec::new();
for (name, profile) in profiles.iter() { for (name, profile) in profiles.iter() {
let target = chunk.remove(name).unwrap(); let target = chunk.remove(name).unwrap();
self.clone().deploy_node(parent.clone(), target, profile.clone()).await?; futures.push(self.clone().deploy_node(parent.clone(), target, profile.clone()));
} }
let result: NixResult<Vec<()>> = join_all(futures).await.into_iter().collect();
result?;
// Create GC root // Create GC root
if self.options.create_gc_roots { if self.options.create_gc_roots {
let job = parent.create_job(JobType::CreateGcRoots, nodes.clone())?; let job = parent.create_job(JobType::CreateGcRoots, nodes.clone())?;