From 2c8d2c6a1545e8f490643c542a579584f7b4dec2 Mon Sep 17 00:00:00 2001
From: Leo Gordon <lg4@ebi.ac.uk>
Date: Mon, 6 Oct 2014 16:31:23 +0100
Subject: [PATCH] API change: Limiter::preliminary_offer reports hitting the
 limit; produce detailed output of negotiations

---
 modules/Bio/EnsEMBL/Hive/Limiter.pm   |  6 ++++--
 modules/Bio/EnsEMBL/Hive/Scheduler.pm | 19 ++++++++++++-------
 modules/Bio/EnsEMBL/Hive/Worker.pm    |  3 ++-
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Hive/Limiter.pm b/modules/Bio/EnsEMBL/Hive/Limiter.pm
index f443146c1..a1579cf74 100644
--- a/modules/Bio/EnsEMBL/Hive/Limiter.pm
+++ b/modules/Bio/EnsEMBL/Hive/Limiter.pm
@@ -108,10 +108,12 @@ sub preliminary_offer {
         my $product = $available_capacity * $multiplier;
         my $slots_available = int( "$product" );            # stringification helps to round up things like 0.1*10 (instead of leaving them at 0.99999999)
 
-        return ($slots_available<$slots_asked) ? $slots_available : $slots_asked;
+        my $hit_the_limit = $slots_available<$slots_asked;
+
+        return ($hit_the_limit ? $slots_available : $slots_asked , $hit_the_limit);
     }
 
-    return $slots_asked;
+    return ($slots_asked, 0);
 }
 
 
diff --git a/modules/Bio/EnsEMBL/Hive/Scheduler.pm b/modules/Bio/EnsEMBL/Hive/Scheduler.pm
index 754a29501..6f12a7e85 100644
--- a/modules/Bio/EnsEMBL/Hive/Scheduler.pm
+++ b/modules/Bio/EnsEMBL/Hive/Scheduler.pm
@@ -261,15 +261,20 @@ sub schedule_workers {
                     : (),
             );
 
+            my $hit_the_limit;
+
                 # negotiations:
             foreach my $limiter (@limiters) {
-                $extra_workers_this_analysis = $limiter->preliminary_offer( $extra_workers_this_analysis );
-            }
-
-                # do not continue with this analysis if limiters haven't agreed on a positive number:
-            if ($extra_workers_this_analysis <= 0) {
-                push @$log_buffer, "Although Analysis '$logic_name' needed extra workers, it is being skipped because of activated limiters.";
-                next;
+                ($extra_workers_this_analysis, $hit_the_limit) = $limiter->preliminary_offer( $extra_workers_this_analysis );
+
+                if($hit_the_limit) {
+                    if($extra_workers_this_analysis>0) {
+                        push @$log_buffer, "Hit the limit of *** ".$limiter->description." ***, settling for $extra_workers_this_analysis Workers.";
+                    } else {
+                        push @$log_buffer, "Hit the limit of *** ".$limiter->description." ***, skipping this Analysis.";
+                        next;
+                    }
+                }
             }
 
                 # let all parties know the final decision of negotiations:
diff --git a/modules/Bio/EnsEMBL/Hive/Worker.pm b/modules/Bio/EnsEMBL/Hive/Worker.pm
index 5b73c8743..ef750b083 100644
--- a/modules/Bio/EnsEMBL/Hive/Worker.pm
+++ b/modules/Bio/EnsEMBL/Hive/Worker.pm
@@ -490,7 +490,8 @@ sub run {
 
                 } else {
                     my $desired_batch_size  = $current_role->analysis->stats->get_or_estimate_batch_size();
-                    $desired_batch_size     = $self->job_limiter->preliminary_offer( $desired_batch_size );
+                    my $hit_the_limit;  # dummy at the moment
+                    ($desired_batch_size, $hit_the_limit)   = $self->job_limiter->preliminary_offer( $desired_batch_size );
 
                     my $actual_batch = $job_adaptor->grab_jobs_for_role( $current_role, $desired_batch_size );
                     if(scalar(@$actual_batch)) {
-- 
GitLab