about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/build-remote.pl.in12
-rw-r--r--src/libstore/build.cc13
2 files changed, 18 insertions, 7 deletions
diff --git a/scripts/build-remote.pl.in b/scripts/build-remote.pl.in
index a7023cb4dff3..33b943602315 100755
--- a/scripts/build-remote.pl.in
+++ b/scripts/build-remote.pl.in
@@ -23,10 +23,8 @@ use English '-no_match_vars';
 
 my $loadIncreased = 0;
 
-my $amWilling = shift @ARGV;
-my $localSystem = shift @ARGV;
-my $neededSystem = shift @ARGV;
-my $drvPath = shift @ARGV;
+my ($amWilling, $localSystem, $neededSystem, $drvPath, $mustRun) = @ARGV;
+$mustRun = 0 unless defined $mustRun;
 
 sub sendReply {
     my $reply = shift;
@@ -91,13 +89,15 @@ LOOP: foreach my $cur (@machines) {
         # We have a machine of the right type.  Try to get a lock on
         # one of the machine's lock files.
         my $slot = 0;
-        while ($slot < $cur->{maxJobs}) {
+        while ($slot < $cur->{maxJobs} || $mustRun) {
             my $slotLock = "$currentLoad/" . $cur->{systemType} . "-" . $cur->{hostName} . "-$slot";
             open SLOTLOCK, ">>$slotLock" or die;
             if (flock(SLOTLOCK, LOCK_EX | LOCK_NB)) {
+                print STDERR "warning: exceeding maximum load on " . $cur->{systemType} . "\n"
+                    if $slot >= $cur->{maxJobs};
                 $machine = $cur;
                 last LOOP;
-            }                
+            }
             close SLOTLOCK;
             $slot++;
         }
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index a1c99cddd040..fbec67598708 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -219,6 +219,9 @@ public:
     /* Can we start another child process? */
     bool canBuildMore();
 
+    /* Can we postpone a build right now? */
+    bool canPostpone();
+
     /* Registers a running child process.  `inBuildSlot' means that
        the process counts towards the jobs limit. */
     void childStarted(GoalPtr goal, pid_t pid,
@@ -1296,7 +1299,9 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook()
                 (worker.canBuildMore() ? (string) "1" : "0").c_str(),
                 thisSystem.c_str(),
                 drv.platform.c_str(),
-                drvPath.c_str(), NULL);
+                drvPath.c_str(),
+                (worker.canPostpone() ? (string) "0" : "1").c_str(),
+                NULL);
             
             throw SysError(format("executing `%1%'") % buildHook);
             
@@ -2602,6 +2607,12 @@ bool Worker::canBuildMore()
 }
 
 
+bool Worker::canPostpone()
+{
+    return children.size() != 0;
+}
+
+
 void Worker::childStarted(GoalPtr goal,
     pid_t pid, const set<int> & fds, bool inBuildSlot)
 {