From 09a4c9fad25cdaad67fcf2c02351b58a7eec4f3f Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <edolstra@gmail.com>
Date: Wed, 16 May 2018 14:22:00 +0200
Subject: [PATCH] hydra-evaluator: Allow setting the maximum number of
 concurrent evaluations

---
 src/hydra-evaluator/hydra-evaluator.cc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/hydra-evaluator/hydra-evaluator.cc b/src/hydra-evaluator/hydra-evaluator.cc
index e7d619b3..86ac5c39 100644
--- a/src/hydra-evaluator/hydra-evaluator.cc
+++ b/src/hydra-evaluator/hydra-evaluator.cc
@@ -1,6 +1,7 @@
-#include "shared.hh"
 #include "db.hh"
+#include "hydra-config.hh"
 #include "pool.hh"
+#include "shared.hh"
 
 #include <algorithm>
 #include <thread>
@@ -16,6 +17,8 @@ typedef std::pair<std::string, std::string> JobsetName;
 
 struct Evaluator
 {
+    std::unique_ptr<Config> config;
+
     nix::Pool<Connection> dbPool;
 
     struct Jobset
@@ -30,7 +33,7 @@ struct Evaluator
 
     std::experimental::optional<JobsetName> evalOne;
 
-    size_t maxEvals = 4;
+    const size_t maxEvals;
 
     struct State
     {
@@ -45,6 +48,11 @@ struct Evaluator
 
     const time_t notTriggered = std::numeric_limits<time_t>::max();
 
+    Evaluator()
+        : config(std::make_unique<::Config>())
+        , maxEvals(std::max((size_t) 1, (size_t) config->getIntOption("max_concurrent_evals", 4)))
+    { }
+
     void readJobsets()
     {
         auto conn(dbPool.get());