Merge pull request #804 from grahamc/fully-static-jobsets
declarative projects: support fully static, declarative configuration
This commit is contained in:
@ -21,6 +21,7 @@ our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
updateDeclarativeJobset
|
||||
handleDeclarativeJobsetBuild
|
||||
handleDeclarativeJobsetJson
|
||||
);
|
||||
|
||||
|
||||
@ -65,6 +66,22 @@ sub updateDeclarativeJobset {
|
||||
});
|
||||
};
|
||||
|
||||
sub handleDeclarativeJobsetJson {
|
||||
my ($db, $project, $declSpec) = @_;
|
||||
$db->txn_do(sub {
|
||||
my @kept = keys %$declSpec;
|
||||
push @kept, ".jobsets";
|
||||
$project->jobsets->search({ name => { "not in" => \@kept } })->update({ enabled => 0, hidden => 1 });
|
||||
while ((my $jobsetName, my $spec) = each %$declSpec) {
|
||||
eval {
|
||||
updateDeclarativeJobset($db, $project, $jobsetName, $spec);
|
||||
1;
|
||||
} or do {
|
||||
print STDERR "ERROR: failed to process declarative jobset ", $project->name, ":${jobsetName}, ", $@, "\n";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sub handleDeclarativeJobsetBuild {
|
||||
my ($db, $project, $build) = @_;
|
||||
@ -82,19 +99,7 @@ sub handleDeclarativeJobsetBuild {
|
||||
};
|
||||
|
||||
my $declSpec = decode_json($declText);
|
||||
$db->txn_do(sub {
|
||||
my @kept = keys %$declSpec;
|
||||
push @kept, ".jobsets";
|
||||
$project->jobsets->search({ name => { "not in" => \@kept } })->update({ enabled => 0, hidden => 1 });
|
||||
while ((my $jobsetName, my $spec) = each %$declSpec) {
|
||||
eval {
|
||||
updateDeclarativeJobset($db, $project, $jobsetName, $spec);
|
||||
1;
|
||||
} or do {
|
||||
print STDERR "ERROR: failed to process declarative jobset ", $project->name, ":${jobsetName}, ", $@, "\n";
|
||||
}
|
||||
}
|
||||
});
|
||||
handleDeclarativeJobsetJson($db, $project, $declSpec);
|
||||
1;
|
||||
} or do {
|
||||
# note the error in the database in the case eval fails for whatever reason
|
||||
|
@ -569,10 +569,28 @@ sub checkJobsetWrapped {
|
||||
eval {
|
||||
$declSpec = decode_json($declText);
|
||||
};
|
||||
|
||||
die "Declarative specification file $declFile not valid JSON: $@\n" if $@;
|
||||
updateDeclarativeJobset($db, $project, ".jobsets", $declSpec);
|
||||
$jobset->discard_changes;
|
||||
$inputInfo->{"declInput"} = [ $declInput ];
|
||||
|
||||
if (ref $declSpec eq "HASH") {
|
||||
if (grep ref $_ eq "HASH", values %$declSpec) {
|
||||
# Since all of its keys are hashes, assume the json document
|
||||
# itself is the entire set of jobs
|
||||
handleDeclarativeJobsetJson($db, $project, $declSpec);
|
||||
$db->txn_do(sub {
|
||||
$jobset->update({ lastcheckedtime => time, fetcherrormsg => undef });
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
# Update the jobset with the spec's inputs, and the continue
|
||||
# evaluating the .jobsets jobset.
|
||||
updateDeclarativeJobset($db, $project, ".jobsets", $declSpec);
|
||||
$jobset->discard_changes;
|
||||
$inputInfo->{"declInput"} = [ $declInput ];
|
||||
}
|
||||
} else {
|
||||
die "Declarative specification file $declFile is not a dictionary"
|
||||
}
|
||||
}
|
||||
|
||||
# Fetch all values for all inputs.
|
||||
|
Reference in New Issue
Block a user