From 96b3c6cd5b04441401bfe33ee6019c069366a6e2 Mon Sep 17 00:00:00 2001
From: Leo Gordon <lg4@ebi.ac.uk>
Date: Wed, 21 Nov 2012 12:23:11 +0000
Subject: [PATCH] (multi-meadow scheduler) restrict the set of analyses that a
 worker with a given meadow_type can specialize into

---
 modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm | 9 ++++++---
 modules/Bio/EnsEMBL/Hive/Queen.pm                      | 7 ++++---
 modules/Bio/EnsEMBL/Hive/Scheduler.pm                  | 2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm b/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm
index 677d28c7a..646cf32b4 100644
--- a/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm
+++ b/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm
@@ -79,10 +79,13 @@ sub fetch_by_analysis_id {
 }
 
 
-sub fetch_all_by_suitability_rc_id {
-    my ($self, $resource_class_id) = @_;
+sub fetch_all_by_suitability_rc_id_meadow_type {
+    my ($self, $resource_class_id, $meadow_type) = @_;
 
-    my $join = [[['analysis_base', 'a'], " ast.analysis_id=a.analysis_id ".( $resource_class_id ? "AND a.resource_class_id=$resource_class_id " : '') ]];
+    my $join = [[ ['analysis_base', 'a'], " ast.analysis_id=a.analysis_id "
+                                                .( $resource_class_id ? "AND a.resource_class_id=$resource_class_id " : '')
+                                                .( $meadow_type       ? "AND (a.meadow_type IS NULL OR a.meadow_type='$meadow_type') " : '')
+               ]];
 
         # the ones that clearly have work to do:
         #
diff --git a/modules/Bio/EnsEMBL/Hive/Queen.pm b/modules/Bio/EnsEMBL/Hive/Queen.pm
index aa56dc62a..14b280ba1 100644
--- a/modules/Bio/EnsEMBL/Hive/Queen.pm
+++ b/modules/Bio/EnsEMBL/Hive/Queen.pm
@@ -257,7 +257,7 @@ sub specialize_new_worker {
 
     } else {    # probably scheduled by beekeeper.pl
 
-        $stats = $self->suggest_analysis_to_specialize_by_rc_id($worker->resource_class_id)
+        $stats = $self->suggest_analysis_to_specialize_by_rc_id_meadow_type($worker->resource_class_id, $worker->meadow_type)
             or die "Queen failed to pick an analysis for the worker";
 
         print "Queen picked analysis with dbID=".$stats->analysis_id." for the worker\n";
@@ -838,11 +838,12 @@ sub register_all_workers_dead {
 }
 
 
-sub suggest_analysis_to_specialize_by_rc_id {
+sub suggest_analysis_to_specialize_by_rc_id_meadow_type {
     my $self                = shift;
     my $rc_id               = shift;
+    my $meadow_type         = shift;
 
-    my @suitable_analyses = @{ $self->db->get_AnalysisStatsAdaptor->fetch_all_by_suitability_rc_id( $rc_id ) };
+    my @suitable_analyses = @{ $self->db->get_AnalysisStatsAdaptor->fetch_all_by_suitability_rc_id_meadow_type( $rc_id, $meadow_type ) };
 
     foreach my $stats (@suitable_analyses) {
 
diff --git a/modules/Bio/EnsEMBL/Hive/Scheduler.pm b/modules/Bio/EnsEMBL/Hive/Scheduler.pm
index b4996490a..2760e7591 100644
--- a/modules/Bio/EnsEMBL/Hive/Scheduler.pm
+++ b/modules/Bio/EnsEMBL/Hive/Scheduler.pm
@@ -64,7 +64,7 @@ sub schedule_workers {
 
     my @suitable_analyses   = $filter_analysis
                                 ? ( $filter_analysis->stats )
-                                : @{ $queen->db->get_AnalysisStatsAdaptor->fetch_all_by_suitability_rc_id() };
+                                : @{ $queen->db->get_AnalysisStatsAdaptor->fetch_all_by_suitability_rc_id_meadow_type() };
 
     unless(@suitable_analyses) {
         print "Scheduler could not find any suitable analyses to start with\n";
-- 
GitLab