diff --git a/src/HydraFrontend/lib/HydraFrontend/Controller/Root.pm b/src/HydraFrontend/lib/HydraFrontend/Controller/Root.pm index 365a6fe1..956c044c 100644 --- a/src/HydraFrontend/lib/HydraFrontend/Controller/Root.pm +++ b/src/HydraFrontend/lib/HydraFrontend/Controller/Root.pm @@ -31,8 +31,8 @@ sub index :Path :Args(0) { $c->stash->{template} = 'index.tt'; $c->stash->{allBuilds} = [$c->model('DB::Builds')->all]; # Get the latest build for each unique job. - # select * from builds as x where timestamp == (select max(timestamp) from builds where name == x.name); - $c->stash->{latestBuilds} = [$c->model('DB::Builds')->search(undef, {order_by => "name", where => "timestamp == (select max(timestamp) from builds where name == me.name)"})]; + # select * from builds as x where timestamp == (select max(timestamp) from builds where jobName == x.jobName); + $c->stash->{latestBuilds} = [$c->model('DB::Builds')->search(undef, {order_by => "jobName", where => "timestamp == (select max(timestamp) from builds where jobName == me.jobName)"})]; } @@ -40,7 +40,7 @@ sub job :Local { my ( $self, $c, $jobName ) = @_; $c->stash->{template} = 'job.tt'; $c->stash->{jobName} = $jobName; - $c->stash->{builds} = [$c->model('DB::Builds')->search({name => $jobName}, {order_by => "timestamp DESC"})]; + $c->stash->{builds} = [$c->model('DB::Builds')->search({jobName => $jobName}, {order_by => "timestamp DESC"})]; } diff --git a/src/HydraFrontend/lib/HydraFrontend/Schema.pm b/src/HydraFrontend/lib/HydraFrontend/Schema.pm index ab88c044..88921f2f 100644 --- a/src/HydraFrontend/lib/HydraFrontend/Schema.pm +++ b/src/HydraFrontend/lib/HydraFrontend/Schema.pm @@ -8,8 +8,8 @@ use base 'DBIx::Class::Schema'; __PACKAGE__->load_classes; -# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-10-25 22:23:27 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:iW1lrJQVyiDiAYhJBy9/iQ +# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-10-28 17:59:29 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Fayli8dtSdcAYhfKSZnJwg # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/HydraFrontend/lib/HydraFrontend/Schema/Buildlogs.pm b/src/HydraFrontend/lib/HydraFrontend/Schema/Buildlogs.pm index 35bcbf26..08edcfef 100644 --- a/src/HydraFrontend/lib/HydraFrontend/Schema/Buildlogs.pm +++ b/src/HydraFrontend/lib/HydraFrontend/Schema/Buildlogs.pm @@ -25,8 +25,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-10-25 22:23:27 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:01Br5qFsV84USpzqnjk7cw +# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-10-28 17:59:29 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xXiHLBKW5fHl7ukdYeIsTw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/HydraFrontend/lib/HydraFrontend/Schema/Buildproducts.pm b/src/HydraFrontend/lib/HydraFrontend/Schema/Buildproducts.pm index bfc63dee..e9101f8b 100644 --- a/src/HydraFrontend/lib/HydraFrontend/Schema/Buildproducts.pm +++ b/src/HydraFrontend/lib/HydraFrontend/Schema/Buildproducts.pm @@ -25,8 +25,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-10-25 22:23:27 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jYe9p4xG2Ujnf6TsfeE7tA +# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-10-28 17:59:29 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:5SPq4at2/NRvbax49TwfDw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/HydraFrontend/lib/HydraFrontend/Schema/Builds.pm b/src/HydraFrontend/lib/HydraFrontend/Schema/Builds.pm index 7b2bb07e..562c03de 100644 --- a/src/HydraFrontend/lib/HydraFrontend/Schema/Builds.pm +++ b/src/HydraFrontend/lib/HydraFrontend/Schema/Builds.pm @@ -12,7 +12,7 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 0, size => undef }, "timestamp", { data_type => "integer", is_nullable => 0, size => undef }, - "name", + "jobname", { data_type => "text", is_nullable => 0, size => undef }, "description", { data_type => "text", is_nullable => 0, size => undef }, @@ -20,23 +20,31 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 0, size => undef }, "outpath", { data_type => "text", is_nullable => 0, size => undef }, + "iscachedbuild", + { data_type => "integer", is_nullable => 0, size => undef }, "buildstatus", { data_type => "integer", is_nullable => 0, size => undef }, + "errormsg", + { data_type => "text", is_nullable => 0, size => undef }, + "starttime", + { data_type => "integer", is_nullable => 0, size => undef }, + "stoptime", + { data_type => "integer", is_nullable => 0, size => undef }, ); __PACKAGE__->set_primary_key("id"); -__PACKAGE__->has_many( - "buildlogs", - "HydraFrontend::Schema::Buildlogs", - { "foreign.buildid" => "self.id" }, -); __PACKAGE__->has_many( "buildproducts", "HydraFrontend::Schema::Buildproducts", { "foreign.buildid" => "self.id" }, ); +__PACKAGE__->has_many( + "buildlogs", + "HydraFrontend::Schema::Buildlogs", + { "foreign.buildid" => "self.id" }, +); -# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-10-25 22:23:27 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gxVH+2KWcgU41JOl9BbHFA +# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-10-28 17:59:29 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gp6ZZpDA2VzgnNE9NX99dA 1; diff --git a/src/HydraFrontend/root/build.tt b/src/HydraFrontend/root/build.tt index 3d6f4beb..57c7534f 100644 --- a/src/HydraFrontend/root/build.tt +++ b/src/HydraFrontend/root/build.tt @@ -12,7 +12,7 @@
Below are the latest builds for each job.
+Id | Job | Timestamp | Description | [% build.id %] | -[% build.name %] | +[% build.jobname %] | [% date.format(build.timestamp, '%Y-%m-%d %H:%M:%S') %] | [% build.description %] | diff --git a/src/hydra.schema b/src/hydra.schema index f9cec9f4..c707b6d7 100644 --- a/src/hydra.schema +++ b/src/hydra.schema @@ -1,11 +1,15 @@ create table builds ( id integer primary key autoincrement not null, timestamp integer not null, -- time this build was added to the db (in Unix time) - name text not null, + jobName text not null, description text, drvPath text not null, outPath text not null, - buildStatus integer -- 0 = succeeded, 1 = failure, ... + isCachedBuild integer not null, -- boolean + buildStatus integer, -- 0 = succeeded, 1 = Nix build failure, 2 = positive build failure + errorMsg text, -- error message in case of a Nix failure + startTime integer, -- in Unix time, 0 = used cached build result + stopTime integer ); diff --git a/src/scheduler.pl b/src/scheduler.pl index cb57741d..f69f6ffc 100644 --- a/src/scheduler.pl +++ b/src/scheduler.pl @@ -30,35 +30,48 @@ foreach my $jobName (keys %{$jobs->{item}}) { my $outPath = $job->{outPath}; my $drvPath = $job->{drvPath}; - if (scalar(@{$dbh->selectall_arrayref("select * from builds where name = ? and outPath = ?", {}, $jobName, $outPath)}) > 0) { + if (scalar(@{$dbh->selectall_arrayref("select * from builds where jobName = ? and outPath = ?", {}, $jobName, $outPath)}) > 0) { print " already done\n"; next; } - my $res = system("nix-build $jobsFile --attr $jobName"); + my $isCachedBuild = 1; + my $buildStatus = 0; + my $startTime = 0; + my $stopTime = 0; + + if (system("nix-store --check-validity $outPath 2> /dev/null") != 0) { + $isCachedBuild = 0; - my $buildStatus = $res == 0 ? 0 : 1; + $startTime = time(); + + my $res = system("nix-build $jobsFile --attr $jobName"); + + $stopTime = time(); + + $buildStatus = $res == 0 ? 0 : 1; + } $dbh->begin_work; - $dbh->prepare("insert into builds(timestamp, name, description, drvPath, outPath, buildStatus) values(?, ?, ?, ?, ?, ?)") - ->execute(time(), $jobName, $description, $drvPath, $outPath, $buildStatus); + $dbh->prepare("insert into builds(timestamp, jobName, description, drvPath, outPath, isCachedBuild, buildStatus, errorMsg, startTime, stopTime) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") + ->execute(time(), $jobName, $description, $drvPath, $outPath, $isCachedBuild, $buildStatus, "", $startTime, $stopTime); my $buildId = $dbh->last_insert_id(undef, undef, undef, undef); print " db id = $buildId\n"; + my $logPath = "/nix/var/log/nix/drvs/" . basename $drvPath; + if (-e $logPath) { + print " LOG $logPath\n"; + $dbh->prepare("insert into buildLogs(buildId, logPhase, path, type) values(?, ?, ?, ?)") + ->execute($buildId, "full", $logPath, "raw"); + } + if ($buildStatus == 0) { $dbh->prepare("insert into buildProducts(buildId, type, subtype, path) values(?, ?, ?, ?)") ->execute($buildId, "nix-build", "", $outPath); - my $logPath = "/nix/var/log/nix/drvs/" . basename $drvPath; - if (-e $logPath) { - print " LOG $logPath\n"; - $dbh->prepare("insert into buildLogs(buildId, logPhase, path, type) values(?, ?, ?, ?)") - ->execute($buildId, "full", $logPath, "raw"); - } - if (-e "$outPath/log") { foreach my $logPath (glob "$outPath/log/*") { print " LOG $logPath\n";
---|