AnalysisStats.pm 3.66 KB
Newer Older
1 2 3 4 5 6 7 8
#
# You may distribute this module under the same terms as perl itself
#
# POD documentation - main docs before the code

=pod 

=head1 NAME
9
  Bio::EnsEMBL::Hive::AnalysisStats
10 11 12 13 14 15

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 CONTACT
16 17
  Contact Jessica Severin on EnsEMBL::Hive implemetation/design detail: jessica@ebi.ac.uk
  Contact Ewan Birney on EnsEMBL in general: birney@sanger.ac.uk
18 19

=head1 APPENDIX
20 21
  The rest of the documentation details each of the object methods.
  Internal methods are usually preceded with a _
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
=cut

package Bio::EnsEMBL::Hive::AnalysisStats;

use strict;

use Bio::EnsEMBL::Root;
use Bio::EnsEMBL::Analysis;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Hive::Worker;

use vars qw(@ISA);

@ISA = qw(Bio::EnsEMBL::Root);

=head3
CREATE TABLE analysis_stats (
  analysis_id           int(10) NOT NULL,
  status                enum('BLOCKED', 'READY', 'WORKING', 'ALL_CLAIMED', 'DONE')
                          DEFAULT 'READY' NOT NULL,
  batch_size            int(10) NOT NULL,
  hive_capacity         int(10) NOT NULL,
  total_job_count       int(10) NOT NULL,
  unclaimed_job_count   int(10) NOT NULL,
  done_job_count        int(10) NOT NULL,
  num_required_workers  int(10) NOT NULL,
  last_update           datetime NOT NULL,

  UNIQUE KEY   (analysis_id)
);
=cut


sub adaptor {
  my $self = shift;
  $self->{'_adaptor'} = shift if(@_);
  return $self->{'_adaptor'};
}

61 62 63 64 65 66
sub update {
  my $self = shift;
  return unless($self->adaptor);
  $self->adaptor->update($self);
}

67
sub analysis_id {
68
  my $self = shift;
69 70
  $self->{'_analysis_id'} = shift if(@_);
  return $self->{'_analysis_id'};
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
}

sub status {
  my ($self, $value ) = @_;

  if(defined $value) {
    $self->{'_status'} = $value;
  }
  return $self->{'_status'};
}

sub batch_size {
  my $self = shift;
  $self->{'_batch_size'} = shift if(@_);
  return $self->{'_batch_size'};
}

sub hive_capacity {
  my $self = shift;
  $self->{'_hive_capacity'} = shift if(@_);
  return $self->{'_hive_capacity'};
}

sub total_job_count {
  my $self = shift;
  $self->{'_total_job_count'} = shift if(@_);
  return $self->{'_total_job_count'};
}

sub unclaimed_job_count {
  my $self = shift;
  $self->{'_unclaimed_job_count'} = shift if(@_);
  return $self->{'_unclaimed_job_count'};
}

sub done_job_count {
  my $self = shift;
  $self->{'_done_job_count'} = shift if(@_);
  return $self->{'_done_job_count'};
}

sub num_required_workers {
  my $self = shift;
  $self->{'_num_required_workers'} = shift if(@_);
  return $self->{'_num_required_workers'};
}

sub seconds_since_last_update {
  my( $self, $value ) = @_;
  $self->{'_last_update'} = time() + $value if(defined($value));
  return time() - $self->{'_last_update'};
}

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
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;
}
  
143 144
sub print_stats {
  my $self = shift;
145
  print("ANALYSIS_STATS: analysis_id=",$self->analysis_id,"\n"
146 147 148 149 150 151 152 153 154 155 156
       ," status=",$self->status,"\n"
       ," batch_size=",$self->batch_size,"\n"
       ," hive_capacity=" . $self->hive_capacity(),"\n"
       ,",total_job_count=" . $self->total_job_count(),"\n"
       ,",unclaimed_job_count=" . $self->unclaimed_job_count(),"\n"
       ,",done_job_count=" . $self->done_job_count(),"\n"
       ,",num_required_workers=" . $self->num_required_workers(),"\n"
       ,",last_update==", $self->{'_last_update'},"\n");
}

1;