diff --git a/modules/Bio/EnsEMBL/Hive/Queen.pm b/modules/Bio/EnsEMBL/Hive/Queen.pm index 5d9f0582c8f10836333fc2b54e9c9df443434f9d..76633ad9a128e403e0b80b70857982835fc4bed9 100755 --- a/modules/Bio/EnsEMBL/Hive/Queen.pm +++ b/modules/Bio/EnsEMBL/Hive/Queen.pm @@ -131,7 +131,7 @@ sub create_new_worker { $beekeeper = '' unless($beekeeper); my $sql = "INSERT INTO hive SET born=now(), last_check_in=now(), " . - "process_id=?, analysis_id=?, beekeeper=?, host=?"; + "process_id=?, analysis_id=?, beekeeper=?, host=?"; my $sth = $self->prepare($sql); $sth->execute($pid, $analysisStats->analysis_id, $beekeeper, $host); @@ -255,69 +255,69 @@ sub synchronize_hive { sub synchronize_AnalysisStats { my $self = shift; - my $analysisStats = shift; + my $analysisStats = shift; return $analysisStats unless($analysisStats); - return $analysisStats unless($analysisStats->analysis_id); - return $analysisStats if($analysisStats->status eq 'BLOCKED'); - return $analysisStats if($analysisStats->status eq 'SYNCHING'); + return $analysisStats unless($analysisStats->analysis_id); + return $analysisStats if($analysisStats->status eq 'BLOCKED'); + return $analysisStats if($analysisStats->status eq 'SYNCHING'); $analysisStats->update_status('SYNCHING'); - $analysisStats->total_job_count(0); - $analysisStats->unclaimed_job_count(0); - $analysisStats->done_job_count(0); - $analysisStats->failed_job_count(0); - $analysisStats->num_required_workers(0); - - my $sql = "SELECT status, count(*) FROM analysis_job ". - "WHERE analysis_id=? GROUP BY status"; - my $sth = $self->prepare($sql); - $sth->execute($analysisStats->analysis_id); - - while (my ($status, $count)=$sth->fetchrow_array()) { - - my $total = $analysisStats->total_job_count(); - $analysisStats->total_job_count($total + $count); - - if($status eq 'READY') { - $analysisStats->unclaimed_job_count($count); - my $numWorkers = $count/$analysisStats->batch_size; - $numWorkers=1 if($numWorkers<1); - if($analysisStats->hive_capacity>0 and $numWorkers > $analysisStats->hive_capacity) { - $numWorkers=$analysisStats->hive_capacity; - } - $analysisStats->num_required_workers($numWorkers); - } - if($status eq 'DONE') { $analysisStats->done_job_count($count); } - if($status eq 'FAILED') { $analysisStats->failed_job_count($count); } - } - $sth->finish; - $analysisStats->determine_status(); - + $analysisStats->total_job_count(0); + $analysisStats->unclaimed_job_count(0); + $analysisStats->done_job_count(0); + $analysisStats->failed_job_count(0); + $analysisStats->num_required_workers(0); + + my $sql = "SELECT status, count(*) FROM analysis_job ". + "WHERE analysis_id=? GROUP BY status"; + my $sth = $self->prepare($sql); + $sth->execute($analysisStats->analysis_id); + + while (my ($status, $count)=$sth->fetchrow_array()) { + + my $total = $analysisStats->total_job_count(); + $analysisStats->total_job_count($total + $count); + + if($status eq 'READY') { + $analysisStats->unclaimed_job_count($count); + my $numWorkers = $count/$analysisStats->batch_size; + $numWorkers=1 if($numWorkers<1); + if($analysisStats->hive_capacity>0 and $numWorkers > $analysisStats->hive_capacity) { + $numWorkers=$analysisStats->hive_capacity; + } + $analysisStats->num_required_workers($numWorkers); + } + if($status eq 'DONE') { $analysisStats->done_job_count($count); } + if($status eq 'FAILED') { $analysisStats->failed_job_count($count); } + } + $sth->finish; + $analysisStats->determine_status(); + # # adjust_stats_for_living_workers # - if($analysisStats->hive_capacity > 0) { - my $sql = "SELECT count(*) FROM hive WHERE cause_of_death='' and analysis_id=?"; - $sth = $self->prepare($sql); - $sth->execute($analysisStats->analysis_id); - my($liveCount)=$sth->fetchrow_array(); - $sth->finish; - - my $numWorkers = $analysisStats->num_required_workers; - - my $capacityAdjust = ($numWorkers + $liveCount) - $analysisStats->hive_capacity; - $numWorkers -= $capacityAdjust if($capacityAdjust > 0); - $numWorkers=0 if($numWorkers<0); - - $analysisStats->num_required_workers($numWorkers); + if($analysisStats->hive_capacity > 0) { + my $sql = "SELECT count(*) FROM hive WHERE cause_of_death='' and analysis_id=?"; + $sth = $self->prepare($sql); + $sth->execute($analysisStats->analysis_id); + my($liveCount)=$sth->fetchrow_array(); + $sth->finish; + + my $numWorkers = $analysisStats->num_required_workers; + + my $capacityAdjust = ($numWorkers + $liveCount) - $analysisStats->hive_capacity; + $numWorkers -= $capacityAdjust if($capacityAdjust > 0); + $numWorkers=0 if($numWorkers<0); + + $analysisStats->num_required_workers($numWorkers); } $analysisStats->update; - return $analysisStats; + return $analysisStats; }