Commit 687358d8 authored by Jessica Severin's avatar Jessica Severin
Browse files

refactored the logic for update_analysis_stats so that it updates the stats

on all anlyses, not just the ones with entries in the analysis_job table.
New logic is also faster.
parent 44b38e8a
...@@ -197,45 +197,44 @@ sub fetch_overdue_workers { ...@@ -197,45 +197,44 @@ sub fetch_overdue_workers {
sub update_analysis_stats { sub update_analysis_stats {
my $self = shift; my $self = shift;
my $sql = "SELECT analysis.analysis_id, status, count(*) ". my $allAnalysis = $self->db->get_AnalysisAdaptor->fetch_all;
"FROM analysis_job, analysis ".
"WHERE analysis_job.analysis_id=analysis.analysis_id ".
"GROUP BY analysis_job.analysis_id, status";
my $statsDBA = $self->db->get_AnalysisStatsAdaptor; foreach my $analysis (@$allAnalysis) {
my $analysisStats = undef;
my $sth = $self->prepare($sql); my $analysisStats = $analysis->stats;
$sth->execute(); $analysisStats->total_job_count(0);
while (my ($analysis_id, $status, $count)=$sth->fetchrow_array()) { $analysisStats->unclaimed_job_count(0);
unless(defined($analysisStats) and $analysisStats->analysis_id==$analysis_id) { $analysisStats->done_job_count(0);
$analysisStats->determine_status()->update() if($analysisStats); $analysisStats->failed_job_count(0);
$analysisStats->num_required_workers(0);
$analysisStats = $statsDBA->fetch_by_analysis_id($analysis_id);
$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 $total = $analysisStats->total_job_count(); my $sql = "SELECT status, count(*) FROM analysis_job ".
$analysisStats->total_job_count($total + $count); "WHERE analysis_id=? GROUP BY status";
if($status eq 'READY') { my $sth = $self->prepare($sql);
$analysisStats->unclaimed_job_count($count); $sth->execute($analysis->dbID);
my $numWorkers = $count/$analysisStats->batch_size;
$numWorkers=1 if($numWorkers<1); while (my ($status, $count)=$sth->fetchrow_array()) {
if($analysisStats->hive_capacity>0 and $numWorkers > $analysisStats->hive_capacity) {
$numWorkers=$analysisStats->hive_capacity; 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);
} }
$analysisStats->num_required_workers($numWorkers); if($status eq 'DONE') { $analysisStats->done_job_count($count); }
if($status eq 'FAILED') { $analysisStats->failed_job_count($count); }
} }
if($status eq 'DONE') { $analysisStats->done_job_count($count); } $analysisStats->determine_status()->update() if($analysisStats);
if($status eq 'FAILED') { $analysisStats->failed_job_count($count); } $sth->finish;
} }
$analysisStats->determine_status()->update() if($analysisStats);
$sth->finish;
$self->adjust_stats_for_living_workers(); $self->adjust_stats_for_living_workers();
} }
......
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