Schedule at most 3 builds every 10'

Builds are taking quite some time and we cannot guarantee to run
more than 3 builds every 10 minutes, which translate into 12 parallel
jobs. It is much better to avoid building
up the backlog and leave more builds for the next iteration flow run.

When querying Gerrit we will then need to get the full list of changes
from the past 24h.

Change-Id: I935bf95085a86020effba94c1991497c63523be2
diff --git a/jenkins/gerrit-verifier-flow.groovy b/jenkins/gerrit-verifier-flow.groovy
index d2340f2..2de10ad 100644
--- a/jenkins/gerrit-verifier-flow.groovy
+++ b/jenkins/gerrit-verifier-flow.groovy
@@ -32,13 +32,14 @@
   static int numRetryBuilds = 3
   static int myAccountId = 1022687
   static int waitForResultTimeout = 10000
+  static int maxBuilds = 3
 }
 
 def lastBuild = build.getPreviousSuccessfulBuild()
 
 def lastBuildStartTimeMillis = lastBuild == null ?
   (System.currentTimeMillis() - 1800000) : lastBuild.getStartTimeInMillis()
-def sinceMillis = lastBuildStartTimeMillis - 30000
+def sinceMillis = lastBuildStartTimeMillis - (24 * 3600 * 1000)
 def since = Globals.tsFormat.format(new Date(sinceMillis))
 
 if(lastBuild != null) {
@@ -87,12 +88,16 @@
 }
 
 println "Gerrit has " + acceptedChanges.size() + " change(s) since " + since
+if(acceptedChanges.size() > Globals.maxBuilds) {
+  println "  but I'm building only ${Globals.maxBuilds} of them at the moment"
+}
 println "================================================================================"
 
-acceptedChanges.each { change ->
+def changesTodo = acceptedChanges.reverse().take(Globals.maxBuilds)
+changesTodo.each { change ->
   println(Globals.gerrit + change._number +
           " [" + change.current_revision + "] " + change.subject) }
 
-def builds = acceptedChanges.collect { change -> { -> build("Gerrit-verifier-change", CHANGE_ID: change._number) } }
+def builds = changesTodo.collect { change -> { -> build("Gerrit-verifier-change", CHANGE_ID: change._number) } }
 parallel(builds)