From 17c0bd74cdb379f9b6bd618d417f956772ea40bc Mon Sep 17 00:00:00 2001
From: Leo Gordon <lg4@ebi.ac.uk>
Date: Tue, 23 Sep 2014 12:54:14 +0100
Subject: [PATCH] API change: Q::get_num_failed_analyses() takes an obligatory
 $list_of_analyses and performs API level filtering (may affect speed)

---
 modules/Bio/EnsEMBL/Hive/Queen.pm | 35 +++++++++++++++----------------
 scripts/beekeeper.pl              |  2 +-
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Hive/Queen.pm b/modules/Bio/EnsEMBL/Hive/Queen.pm
index 6474f27c3..65b132e14 100644
--- a/modules/Bio/EnsEMBL/Hive/Queen.pm
+++ b/modules/Bio/EnsEMBL/Hive/Queen.pm
@@ -649,12 +649,10 @@ sub check_nothing_to_run_but_semaphored {   # make sure it is run after a recent
 
 =head2 get_num_failed_analyses
 
-  Arg [1]    : Bio::EnsEMBL::Hive::AnalysisStats object (optional)
-  Example    : if( $self->get_num_failed_analyses( $my_analysis )) { do_something; }
-  Example    : my $num_failed_analyses = $self->get_num_failed_analyses();
-  Description: Reports all failed analyses and returns
-                either the number of total failed (if no $filter_analysis was provided)
-                or 1/0, depending on whether $filter_analysis failed or not.
+  Arg [1]    : $list_of_analyses
+  Example    : my $num_failed_analyses = $self->get_num_failed_analyses( [ $analysis_A, $analysis_B ] );
+  Example    : if( $self->get_num_failed_analyses( [ $analysis_A, $analysis_B, $analysis_C ] )) { do_something; }
+  Description: Reports all failed analyses and returns their number.
   Returntype : int
   Exceptions : none
   Caller     : beekeeper.pl
@@ -662,22 +660,23 @@ sub check_nothing_to_run_but_semaphored {   # make sure it is run after a recent
 =cut
 
 sub get_num_failed_analyses {
-    my ($self, $filter_analysis) = @_;
-
-    my $failed_analyses = $self->db->get_AnalysisAdaptor->fetch_all_failed_analyses();
+    my ($self, $list_of_analyses) = @_;
 
-    my $filter_analysis_failed = 0;
+    my $failed_analyses_counter = 0;
 
-    foreach my $failed_analysis (@$failed_analyses) {
-        warn "\t##########################################################\n";
-        warn "\t# Too many jobs in analysis '".$failed_analysis->logic_name."' FAILED #\n";
-        warn "\t##########################################################\n\n";
-        if($filter_analysis and ($filter_analysis->dbID == $failed_analysis)) {
-            $filter_analysis_failed = 1;
+    foreach my $analysis (@$list_of_analyses) {
+        my $stats = $analysis->stats;
+        if( $stats->status eq 'FAILED') {
+            my $logic_name          = $analysis->logic_name;
+            my $failed_job_count    = $stats->failed_job_count;
+            my $tolerance           = $analysis->failed_job_tolerance;
+            warn "\t##################################################################################################\n";
+            warn "\t# Analysis '$logic_name' has FAILED    (failed Jobs: $failed_job_count, tolerance: $tolerance\%) #\n";
+            warn "\t##################################################################################################\n";
+            $failed_analyses_counter++;
         }
     }
-
-    return $filter_analysis ? $filter_analysis_failed : scalar(@$failed_analyses);
+    return $failed_analyses_counter;
 }
 
 
diff --git a/scripts/beekeeper.pl b/scripts/beekeeper.pl
index 1c42fc107..11e83775e 100755
--- a/scripts/beekeeper.pl
+++ b/scripts/beekeeper.pl
@@ -391,7 +391,7 @@ sub run_autonomously {
             print "Not submitting any workers this iteration\n";
         }
 
-        $failed_analyses       = $queen->get_num_failed_analyses( $run_analysis );
+        $failed_analyses       = $queen->get_num_failed_analyses( $list_of_analyses );
         $num_of_remaining_jobs = $queen->get_remaining_jobs_show_hive_progress( $run_analysis );
 
     } while( $keep_alive
-- 
GitLab