Cleanup eval serialization

Signed-off-by: Shea Levy <shea@shealevy.com>
This commit is contained in:
Shea Levy 2013-10-24 15:38:20 -04:00
parent 917660442e
commit e04477003e
4 changed files with 33 additions and 24 deletions

View file

@ -274,24 +274,7 @@ sub evals_GET {
my $offset = ($page - 1) * $resultsPerPage; my $offset = ($page - 1) * $resultsPerPage;
$c->stash->{evals} = getEvals($self, $c, $evals, $offset, $resultsPerPage); $c->stash->{evals} = getEvals($self, $c, $evals, $offset, $resultsPerPage);
my %entity = ( my %entity = (
evals => [ $evals->search({ 'me.hasnewbuilds' => 1 }, { evals => $c->stash->{evals},
columns => [
'me.hasnewbuilds',
'me.id',
'jobsetevalinputs.name',
'jobsetevalinputs.altnr',
'jobsetevalinputs.revision',
'jobsetevalinputs.type',
'jobsetevalinputs.uri',
'jobsetevalinputs.dependency',
'jobsetevalmembers.build',
],
join => [ 'jobsetevalinputs', 'jobsetevalmembers' ],
collapse => 1,
rows => $resultsPerPage,
offset => $offset,
order_by => "me.id DESC",
}) ],
first => "?page=1", first => "?page=1",
last => "?page=" . POSIX::ceil($c->stash->{total}/$resultsPerPage) last => "?page=" . POSIX::ceil($c->stash->{total}/$resultsPerPage)
); );

View file

@ -169,6 +169,14 @@ __PACKAGE__->belongs_to(
# Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-06-13 01:54:50 # Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-06-13 01:54:50
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1Dp8B58leBLh4GK0GPw2zg # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1Dp8B58leBLh4GK0GPw2zg
my %hint = (
columns => [
"revision"
],
);
sub json_hint {
return \%hint;
}
# You can replace this text with custom code or comments, and it will be preserved on regeneration
1; 1;

View file

@ -199,4 +199,22 @@ __PACKAGE__->has_many(
__PACKAGE__->many_to_many(builds => 'buildIds', 'build'); __PACKAGE__->many_to_many(builds => 'buildIds', 'build');
my %hint = (
columns => [
"hasnewbuilds",
"id"
],
relations => {
"builds" => "id"
},
eager_relations => {
# altnr? Does anyone care?
jobsetevalinputs => "name"
}
);
sub json_hint {
return \%hint;
}
1; 1;

View file

@ -1,6 +1,6 @@
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON;
use Test::Simple tests => 10; use Test::Simple tests => 13;
#use Test::Simple tests => 15; #use Test::Simple tests => 15;
my $ua = LWP::UserAgent->new; my $ua = LWP::UserAgent->new;
@ -47,20 +47,20 @@ ok(exists $jobset->{jobsetinputs}->{"my-src"}, "The new jobset has a 'my-src' in
ok($jobset->{jobsetinputs}->{"my-src"}->{jobsetinputalts}->[0] eq "/run/jobset", "The 'my-src' input is in /run/jobset"); ok($jobset->{jobsetinputs}->{"my-src"}->{jobsetinputalts}->[0] eq "/run/jobset", "The 'my-src' input is in /run/jobset");
=begin comment
system("LOGNAME=root NIX_STORE_DIR=/run/nix/store NIX_LOG_DIR=/run/nix/var/log/nix NIX_STATE_DIR=/run/nix/var/nix HYDRA_DATA=/var/lib/hydra HYDRA_DBI='dbi:Pg:dbname=hydra;user=root;' hydra-evaluator sample default"); system("LOGNAME=root NIX_STORE_DIR=/run/nix/store NIX_LOG_DIR=/run/nix/var/log/nix NIX_STATE_DIR=/run/nix/var/nix HYDRA_DATA=/var/lib/hydra HYDRA_DBI='dbi:Pg:dbname=hydra;user=root;' hydra-evaluator sample default");
$result = request_json({ uri => '/jobset/sample/default/evals' }); $result = request_json({ uri => '/jobset/sample/default/evals' });
ok($result->code() == 200, "Can get evals of a jobset"); ok($result->code() == 200, "Can get evals of a jobset");
my $evals = decode_json($result->content())->{evals}; my $evals = decode_json($result->content())->{evals};
my $eval = $evals->[0]; my $eval = $evals->[0];
ok($eval->{hasnewbuilds} == 1, "The first eval of a jobset has new builds"); ok($eval->{eval}->{hasnewbuilds} == 1, "The first eval of a jobset has new builds");
# Ugh, cached for 30s # Ugh, cached for 30s
sleep 30; sleep 30;
system("echo >> /run/jobset/default.nix; LOGNAME=root NIX_STORE_DIR=/run/nix/store NIX_LOG_DIR=/run/nix/var/log/nix NIX_STATE_DIR=/run/nix/var/nix HYDRA_DATA=/var/lib/hydra HYDRA_DBI='dbi:Pg:dbname=hydra;user=root;' hydra-evaluator sample default"); system("echo >> /run/jobset/default.nix; LOGNAME=root NIX_STORE_DIR=/run/nix/store NIX_LOG_DIR=/run/nix/var/log/nix NIX_STATE_DIR=/run/nix/var/nix HYDRA_DATA=/var/lib/hydra HYDRA_DBI='dbi:Pg:dbname=hydra;user=root;' hydra-evaluator sample default");
my $evals = decode_json(request_json({ uri => '/jobset/sample/default/evals' })->content())->{evals}; my $evals = decode_json(request_json({ uri => '/jobset/sample/default/evals' })->content())->{evals};
ok($evals->[0]->{jobsetevalinputs}->[0]->{revision} != $evals->[1]->{jobsetevalinputs}->[0]->{revision}, "Changing a jobset source changes its revision"); ok($evals->[0]->{eval}->{jobsetevalinputs}->{"my-src"}->{revision} != $evals->[1]->{eval}->{jobsetevalinputs}->{"my-src"}->{revision}, "Changing a jobset source changes its revision");
=begin comment
my $build = decode_json(request_json({ uri => "/build/" . $evals->[0]->{jobsetevalmembers}->[0]->{build} })->content()); my $build = decode_json(request_json({ uri => "/build/" . $evals->[0]->{jobsetevalmembers}->[0]->{build} })->content());
ok($build->{job} eq "job", "The build's job name is job"); ok($build->{job} eq "job", "The build's job name is job");