From 109cc35edf29dde584f7b4b7375c1ac639162cbe Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <e.dolstra@tudelft.nl>
Date: Thu, 23 Apr 2009 15:40:36 +0000
Subject: [PATCH] * Randomly permute the order in which builds are added.  This
 is   mainly to prevent all those Nixpkgs builds named "kde*" from   building
 at the same time.  Since they all have the same slow   dependencies (qt,
 kdelibs) this tends to block the buildfarm.

---
 src/script/hydra_scheduler.pl | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/script/hydra_scheduler.pl b/src/script/hydra_scheduler.pl
index 07b14dea..a54afa70 100755
--- a/src/script/hydra_scheduler.pl
+++ b/src/script/hydra_scheduler.pl
@@ -364,6 +364,17 @@ sub inputsToArgs {
 }
 
 
+sub permute {
+    my @list = @_;
+    print scalar @list, "\n";
+    for (my $n = scalar @list - 1; $n > 0; $n--) {
+        my $k = int(rand($n + 1)); # 0 <= $k <= $n 
+        @list[$n, $k] = @list[$k, $n];
+    }
+    return @list;
+}
+
+
 sub checkJobset {
     my ($project, $jobset) = @_;
     my $inputInfo = {};
@@ -392,7 +403,7 @@ sub checkJobset {
         or die "cannot parse XML output";
 
     # Schedule each successfully evaluated job.
-    foreach my $job (@{$jobs->{job}}) {
+    foreach my $job (permute @{$jobs->{job}}) {
         next if $job->{jobName} eq "";
         print "considering job " . $job->{jobName} . "\n";
         checkJob($project, $jobset, $inputInfo, $nixExprInput, $job);