Commit ced91fa6 authored by Jessica Severin's avatar Jessica Severin
Browse files

added method AnalysisStats::determine_status instead of hard coding

this logic into the Queen
parent 98eb2e34
...@@ -58,6 +58,12 @@ sub adaptor { ...@@ -58,6 +58,12 @@ sub adaptor {
return $self->{'_adaptor'}; return $self->{'_adaptor'};
} }
sub update {
my $self = shift;
return unless($self->adaptor);
$self->adaptor->update($self);
}
sub analysis_id { sub analysis_id {
my $self = shift; my $self = shift;
$self->{'_analysis_id'} = shift if(@_); $self->{'_analysis_id'} = shift if(@_);
...@@ -115,6 +121,25 @@ sub seconds_since_last_update { ...@@ -115,6 +121,25 @@ sub seconds_since_last_update {
return time() - $self->{'_last_update'}; return time() - $self->{'_last_update'};
} }
sub determine_status {
my $self = shift;
if($self->status ne 'BLOCKED') {
if($self->done_job_count>0 and
$self->total_job_count == $self->done_job_count) {
$self->status('DONE');
}
if($self->total_job_count == $self->unclaimed_job_count) {
$self->status('READY');
}
if($self->unclaimed_job_count>0 and
$self->total_job_count > $self->unclaimed_job_count) {
$self->status('WORKING');
}
}
return $self;
}
sub print_stats { sub print_stats {
my $self = shift; my $self = shift;
print("ANALYSIS_STATS: analysis_id=",$self->analysis_id,"\n" print("ANALYSIS_STATS: analysis_id=",$self->analysis_id,"\n"
......
...@@ -261,7 +261,7 @@ sub _final_clause { ...@@ -261,7 +261,7 @@ sub _final_clause {
sub update { sub update {
my ($self, $stats) = @_; my ($self, $stats) = @_;
my $sql = "UPDATE analysis_stats SET status='".$stats->status."' "; my $sql = "UPDATE analysis_stats SET status='".$stats->status."' ";
$sql .= ",batch_size=" . $stats->batch_size(); $sql .= ",batch_size=" . $stats->batch_size();
$sql .= ",hive_capacity=" . $stats->hive_capacity(); $sql .= ",hive_capacity=" . $stats->hive_capacity();
......
...@@ -188,19 +188,7 @@ sub update_analysis_stats { ...@@ -188,19 +188,7 @@ sub update_analysis_stats {
$sth->execute(); $sth->execute();
while (my ($analysis_id, $status, $count)=$sth->fetchrow_array()) { while (my ($analysis_id, $status, $count)=$sth->fetchrow_array()) {
unless(defined($analysisStats) and $analysisStats->analysis_id==$analysis_id) { unless(defined($analysisStats) and $analysisStats->analysis_id==$analysis_id) {
if($analysisStats and ($analysisStats->status ne 'BLOCKED')) { $analysisStats->determine_status->update() if($analysisStats);
if($analysisStats->total_job_count == $analysisStats->done_job_count) {
$analysisStats->status('DONE');
}
if($analysisStats->total_job_count == $analysisStats->unclaimed_job_count) {
$analysisStats->status('READY');
}
if($analysisStats->unclaimed_job_count>0 and
$analysisStats->total_job_count > $analysisStats->unclaimed_job_count) {
$analysisStats->status('WORKING');
}
$statsDBA->update($analysisStats);
}
$analysisStats = $statsDBA->fetch_by_analysis_id($analysis_id); $analysisStats = $statsDBA->fetch_by_analysis_id($analysis_id);
$analysisStats->total_job_count(0); $analysisStats->total_job_count(0);
...@@ -215,13 +203,15 @@ sub update_analysis_stats { ...@@ -215,13 +203,15 @@ sub update_analysis_stats {
if($status eq 'READY') { if($status eq 'READY') {
$analysisStats->unclaimed_job_count($count); $analysisStats->unclaimed_job_count($count);
my $numWorkers = $count/$analysisStats->batch_size; my $numWorkers = $count/$analysisStats->batch_size;
if($numWorkers > $analysisStats->hive_capacity) { if($analysisStats->hive_capacity>0 and $numWorkers > $analysisStats->hive_capacity) {
$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 'DONE') { $analysisStats->done_job_count($count); }
} }
$analysisStats->determine_status->update() if($analysisStats);
$sth->finish; $sth->finish;
} }
......
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