From bb7f82840ba6715fd7afcd55a5c2567aaeb5a2a2 Mon Sep 17 00:00:00 2001
From: Rob Vermaas <rob.vermaas@gmail.com>
Date: Wed, 26 May 2010 08:03:59 +0000
Subject: [PATCH] Hydra: Add support for maxSilent meta attribute (also already
 added timeout, but not implemented the actual timeout for the build yet)

---
 src/c/hydra_eval_jobs.cc          |  7 +++++++
 src/lib/Hydra/Helper/AddBuilds.pm |  2 ++
 src/lib/Hydra/Schema/Builds.pm    | 32 +++++++++++++++++++++++++++++--
 src/root/build.tt                 |  4 ++++
 src/script/hydra_build.pl         |  8 +++++---
 src/sql/hydra.sql                 |  2 ++
 6 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/src/c/hydra_eval_jobs.cc b/src/c/hydra_eval_jobs.cc
index fa5599a1..bffbab44 100644
--- a/src/c/hydra_eval_jobs.cc
+++ b/src/c/hydra_eval_jobs.cc
@@ -126,9 +126,16 @@ static void findJobsWrapped(EvalState & state, XMLWriter & doc,
             xmlAttrs["longDescription"] = queryMetaFieldString(meta, "longDescription");
             xmlAttrs["license"] = queryMetaFieldString(meta, "license");
             xmlAttrs["homepage"] = queryMetaFieldString(meta, "homepage");
+
             int prio = queryMetaFieldInt(meta, "schedulingPriority", 100);
             xmlAttrs["schedulingPriority"] = int2String(prio);
 
+            int timeout = queryMetaFieldInt(meta, "timeout", 36000);
+            xmlAttrs["timeout"] = int2String(timeout);
+
+            int maxsilent = queryMetaFieldInt(meta, "maxSilent", 3600);
+            xmlAttrs["maxSilent"] = int2String(maxsilent);
+
             string maintainers;
             MetaValue value = meta["maintainers"];
             if (value.type == MetaValue::tpString)
diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm
index 4d3dc1e0..5d17e63e 100644
--- a/src/lib/Hydra/Helper/AddBuilds.pm
+++ b/src/lib/Hydra/Helper/AddBuilds.pm
@@ -541,6 +541,8 @@ sub checkBuild {
             , license => $buildInfo->{license}
             , homepage => $buildInfo->{homepage}
             , maintainers => $buildInfo->{maintainers}
+            , maxsilent => $buildInfo->{maxSilent}
+            , timeout => $buildInfo->{timeout}
             , nixname => $buildInfo->{nixName}
             , drvpath => $drvPath
             , outpath => $outPath
diff --git a/src/lib/Hydra/Schema/Builds.pm b/src/lib/Hydra/Schema/Builds.pm
index 6a34322d..4c1a6cfb 100644
--- a/src/lib/Hydra/Schema/Builds.pm
+++ b/src/lib/Hydra/Schema/Builds.pm
@@ -128,6 +128,20 @@ __PACKAGE__->table("Builds");
   is_nullable: 1
   size: undef
 
+=head2 maxsilent
+
+  data_type: integer
+  default_value: 3600
+  is_nullable: 1
+  size: undef
+
+=head2 timeout
+
+  data_type: integer
+  default_value: 36000
+  is_nullable: 1
+  size: undef
+
 =head2 iscurrent
 
   data_type: integer
@@ -261,6 +275,20 @@ __PACKAGE__->add_columns(
     is_nullable => 1,
     size => undef,
   },
+  "maxsilent",
+  {
+    data_type => "integer",
+    default_value => 3600,
+    is_nullable => 1,
+    size => undef,
+  },
+  "timeout",
+  {
+    data_type => "integer",
+    default_value => 36000,
+    is_nullable => 1,
+    size => undef,
+  },
   "iscurrent",
   { data_type => "integer", default_value => 0, is_nullable => 1, size => undef },
   "nixexprinput",
@@ -435,8 +463,8 @@ __PACKAGE__->has_many(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-03-05 13:07:46
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sE2/zTcfETC8Eahh6NQDZA
+# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-05-26 09:25:50
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OApfteImw84nYhUvSUB4FA
 
 use Hydra::Helper::Nix;
 
diff --git a/src/root/build.tt b/src/root/build.tt
index c61ab2ff..7bce159e 100644
--- a/src/root/build.tt
+++ b/src/root/build.tt
@@ -274,6 +274,10 @@
 		    <th>System:</th>
 		    <td><tt>[% build.system %]</tt></td>
 		  </tr>
+		  <tr>
+		    <th>Max silent / timeout:</th>
+		    <td>[% build.maxsilent %]s / [% build.timeout %]s</td>
+		  </tr>
 		  <tr>
 		    <th>Derivation store path:</th>
 		    <td>
diff --git a/src/script/hydra_build.pl b/src/script/hydra_build.pl
index a82aeeb7..0a4c251f 100755
--- a/src/script/hydra_build.pl
+++ b/src/script/hydra_build.pl
@@ -209,8 +209,10 @@ sub sendEmailNotification {
 sub doBuild {
     my ($build) = @_;
 
-    my $drvPath = $build->drvpath;
-    my $outPath = $build->outpath;
+    my $drvPath   = $build->drvpath;
+    my $outPath   = $build->outpath;
+    my $maxsilent = $build->maxsilent;
+    my $timeout   = $build->timeout;
 
     my $isCachedBuild = 1;
     my $outputCreated = 1; # i.e., the Nix build succeeded (but it could be a positive failure)
@@ -234,7 +236,7 @@ sub doBuild {
         # to get notifications about specific build steps, the
         # associated log files, etc.
         my $cmd = "nix-store --realise $drvPath " .
-            "--max-silent-time 3600 --keep-going --fallback " .
+            "--max-silent-time $maxsilent --keep-going --fallback " .
             "--no-build-output --log-type flat --print-build-trace " .
             "--add-root " . gcRootFor $outPath . " 2>&1";
 
diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql
index a0ab9ee8..e8ceef59 100644
--- a/src/sql/hydra.sql
+++ b/src/sql/hydra.sql
@@ -143,6 +143,8 @@ create table Builds (
     license       text, -- meta.license
     homepage      text, -- meta.homepage
     maintainers   text, -- meta.maintainers (concatenated, comma-separated)
+    maxsilent     integer default 3600, -- meta.maxsilent
+    timeout       integer default 36000, -- meta.timeout
 
     isCurrent     integer default 0,