Commit 2af05379 authored by Leo Gordon's avatar Leo Gordon
Browse files

simplified output interface from schedule_workers and schedule_workers_resync_if_necessary

parent 2dcf5e7d
...@@ -673,20 +673,17 @@ sub count_running_workers { ...@@ -673,20 +673,17 @@ sub count_running_workers {
sub schedule_workers { sub schedule_workers {
my ($self, $filter_analysis, $orig_pending_by_rc_id, $available_submit_limit) = @_; my ($self, $filter_analysis, $orig_pending_by_rc_id, $available_submit_limit) = @_;
my $statsDBA = $self->db->get_AnalysisStatsAdaptor; my $statsDBA = $self->db->get_AnalysisStatsAdaptor;
my $clearly_needed_analyses = $statsDBA->fetch_by_needed_workers(undef); my $clearly_needed_analyses = $statsDBA->fetch_by_needed_workers(undef);
my $potentially_needed_analyses = $statsDBA->fetch_by_statuses(['LOADING', 'BLOCKED', 'ALL_CLAIMED']); my $potentially_needed_analyses = $statsDBA->fetch_by_statuses(['LOADING', 'BLOCKED', 'ALL_CLAIMED']);
my @all_analyses = (@$clearly_needed_analyses, @$potentially_needed_analyses); my @all_analyses = (@$clearly_needed_analyses, @$potentially_needed_analyses);
return 0 unless(@all_analyses);
my $available_load = 1.0 - $self->get_hive_current_load(); return {} unless(@all_analyses);
return 0 if($available_load <=0.0); my %pending_by_rc_id = %{ $orig_pending_by_rc_id || {} };
my $total_workers_to_run = 0;
my %pending_by_rc_id = %{ $orig_pending_by_rc_id || {} }; my %workers_to_run_by_rc_id = ();
my $total_workers_to_run = 0; my $available_load = 1.0 - $self->get_hive_current_load();
my %workers_to_run_by_rc_id = ();
foreach my $analysis_stats (@all_analyses) { foreach my $analysis_stats (@all_analyses) {
last if ($available_load <= 0.0); last if ($available_load <= 0.0);
...@@ -729,6 +726,8 @@ sub schedule_workers { ...@@ -729,6 +726,8 @@ sub schedule_workers {
$pending_by_rc_id{ $curr_rc_id } -= $pending_this_analysis; $pending_by_rc_id{ $curr_rc_id } -= $pending_this_analysis;
} }
next unless($workers_this_analysis); # do not autovivify the hash by a zero
$total_workers_to_run += $workers_this_analysis; $total_workers_to_run += $workers_this_analysis;
$workers_to_run_by_rc_id{ $curr_rc_id } += $workers_this_analysis; $workers_to_run_by_rc_id{ $curr_rc_id } += $workers_this_analysis;
$analysis_stats->print_stats(); $analysis_stats->print_stats();
...@@ -736,7 +735,7 @@ sub schedule_workers { ...@@ -736,7 +735,7 @@ sub schedule_workers {
} }
printf("Scheduler suggests adding a total of %d workers [%1.5f hive_load remaining]\n", $total_workers_to_run, $available_load); printf("Scheduler suggests adding a total of %d workers [%1.5f hive_load remaining]\n", $total_workers_to_run, $available_load);
return ($total_workers_to_run, \%workers_to_run_by_rc_id); return \%workers_to_run_by_rc_id;
} }
...@@ -751,18 +750,18 @@ sub schedule_workers_resync_if_necessary { ...@@ -751,18 +750,18 @@ sub schedule_workers_resync_if_necessary {
? (($submit_limit<$meadow_limit) ? $submit_limit : $meadow_limit) ? (($submit_limit<$meadow_limit) ? $submit_limit : $meadow_limit)
: (defined($submit_limit) ? $submit_limit : $meadow_limit); : (defined($submit_limit) ? $submit_limit : $meadow_limit);
my ($total_workers_to_run, $workers_to_run_by_rc_id) = $self->schedule_workers($analysis, $pending_by_rc_id, $available_submit_limit); my $workers_to_run_by_rc_id = $self->schedule_workers($analysis, $pending_by_rc_id, $available_submit_limit);
unless( $total_workers_to_run or $self->get_hive_current_load() or $self->count_running_workers() ) { unless( keys %$workers_to_run_by_rc_id or $self->get_hive_current_load() or $self->count_running_workers() ) {
print "*** nothing is running and nothing to do (according to analysis_stats) => perform a hard resync\n" ; print "*** nothing is running and nothing to do (according to analysis_stats) => perform a hard resync\n" ;
$self->check_for_dead_workers($meadow, 1); $self->check_for_dead_workers($meadow, 1);
$self->synchronize_hive($analysis); $self->synchronize_hive($analysis);
($total_workers_to_run, $workers_to_run_by_rc_id) = $self->schedule_workers($analysis, $pending_by_rc_id, $available_submit_limit); $workers_to_run_by_rc_id = $self->schedule_workers($analysis, $pending_by_rc_id, $available_submit_limit);
} }
return ($total_workers_to_run, $workers_to_run_by_rc_id); return $workers_to_run_by_rc_id;
} }
......
...@@ -370,9 +370,9 @@ sub run_autonomously { ...@@ -370,9 +370,9 @@ sub run_autonomously {
$queen->print_analysis_status unless($self->{'no_analysis_stats'}); $queen->print_analysis_status unless($self->{'no_analysis_stats'});
$queen->print_running_worker_status; $queen->print_running_worker_status;
my ($total_workers_to_run, $workers_to_run_by_rc_id) = $queen->schedule_workers_resync_if_necessary($current_meadow, $this_analysis); my $workers_to_run_by_rc_id = $queen->schedule_workers_resync_if_necessary($current_meadow, $this_analysis);
if($total_workers_to_run) { if(keys %$workers_to_run_by_rc_id) {
foreach my $rc_id ( sort { $workers_to_run_by_rc_id->{$a}<=>$workers_to_run_by_rc_id->{$b} } keys %$workers_to_run_by_rc_id) { foreach my $rc_id ( sort { $workers_to_run_by_rc_id->{$a}<=>$workers_to_run_by_rc_id->{$b} } keys %$workers_to_run_by_rc_id) {
my $this_rc_worker_count = $workers_to_run_by_rc_id->{$rc_id}; my $this_rc_worker_count = $workers_to_run_by_rc_id->{$rc_id};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment