[Bio] / Sprout / ERDBLoadGroup.pm Repository:
ViewVC logotype

Diff of /Sprout/ERDBLoadGroup.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Thu Oct 9 17:23:54 2008 UTC revision 1.6, Thu Apr 2 01:37:07 2009 UTC
# Line 77  Line 77 
77    
78  name of this load group  name of this load group
79    
80    =item label
81    
82    name of this worker process
83    
84  =item lastKey  =item lastKey
85    
86  ID of the last major object processed  ID of the last major object processed
# Line 111  Line 115 
115    
116  =head3 new  =head3 new
117    
118      my $edbl = ERDBLoadGroup->new($source, $db, $directory, $options, @tables);      my $edbl = ERDBLoadGroup->new($db, $directory, $options, @tables);
119    
120  Construct a new ERDBLoadGroup object. The following parameters are expected:  Construct a new ERDBLoadGroup object. The following parameters are expected:
121    
122  =over 4  =over 4
123    
 =item source  
   
 The object to be used by the subclass to access the source data. If this parameter  
 is undefined, the source object will be retrieved from the database object as soon  
 as the client calls the L</source> method.  
   
124  =item db  =item db
125    
126  The [[ErdbPm]] object for the database being loaded.  The [[ErdbPm]] object for the database being loaded.
# Line 142  Line 140 
140    
141  sub new {  sub new {
142      # Get the parameters.      # Get the parameters.
143      my ($class, $source, $db, $options, @tables) = @_;      my ($class, $db, $options, @tables) = @_;
144      # Create a statistics object      # Create a statistics object
145      my $stats = Stats->new();      my $stats = Stats->new();
146      # Compute the group name from the class name. It is the first word in      # Compute the group name from the class name. It is the first word in
# Line 160  Line 158 
158                      directory => $directory,                      directory => $directory,
159                      group => $group,                      group => $group,
160                      stats => $stats,                      stats => $stats,
161                      source => $source,                      source => undef,
162                        label => ($options->{label} || $$),
163                      lastKey => undef,                      lastKey => undef,
164                      loaders => {},                      loaders => {},
165                      tables => \@tables,                      tables => \@tables,
# Line 375  Line 374 
374  =item statName  =item statName
375    
376  Name of the statistic to be incremented. This should be a plural noun  Name of the statistic to be incremented. This should be a plural noun
377  describing the object whose kep is coming in.  describing the object whose key is coming in.
378    
379  =item key  =item key
380    
# Line 400  Line 399 
399      # Do we need to output a progress message?      # Do we need to output a progress message?
400      if ($period && T(3) && ($newValue % $period == 0)) {      if ($period && T(3) && ($newValue % $period == 0)) {
401          # Yes.          # Yes.
402          Trace("$newValue $statName processed for $self->{group} group.");          MemTrace("$newValue $statName processed by $self->{label} for $self->{group} group.");
403      }      }
404  }  }
405    
# Line 487  Line 486 
486      $self->{section} = $section;      $self->{section} = $section;
487      # Get the database object.      # Get the database object.
488      my $db = $self->db();      my $db = $self->db();
     # Start a timer and protect ourselves from errors.  
     my $startTime = time();  
     eval {  
489          # Get the list of tables for this group.          # Get the list of tables for this group.
490          my @tables = @{$self->{tables}};          my @tables = @{$self->{tables}};
491        # Should we skip this section?
492        if ($self->SkipIndicated($section, \@tables)) {
493            Trace("Resume mode: section $section skipped for group $self->{group}.") if T(3);
494            $self->Add("section-skips" => 1);
495        } else {
496            # Not skipping. Start a timer and protect ourselves from errors.
497            my $startTime = time();
498            eval {
499          # Get the loader hash.          # Get the loader hash.
500          my $loaderHash = $self->{loaders};          my $loaderHash = $self->{loaders};
501          # Initialize the loaders for the necessary tables.          # Initialize the loaders for the necessary tables.
# Line 510  Line 514 
514          }          }
515          # Generate the data to put in the newly-created load files.          # Generate the data to put in the newly-created load files.
516          $self->Generate();          $self->Generate();
517                # Release our hold on the source object. This allows the database object to
518                # decide whether or not we need a new one.
519                delete $self->{source};
520                # Clean up the database object.
521                $db->Cleanup();
522      };      };
523      # Did it work?      # Did it work?
524      if ($@) {      if ($@) {
# Line 527  Line 536 
536          for my $loader (values %{$self->{loaders}}) {          for my $loader (values %{$self->{loaders}}) {
537              $loader->Finish();              $loader->Finish();
538          }          }
539          # Update the load count and the timer.              # Update the load count.
540          $self->Add("section-loads" => 1);          $self->Add("section-loads" => 1);
541            }
542            # Update the timer.
543          $self->Add(duration => (time() - $startTime));          $self->Add(duration => (time() - $startTime));
544      }      }
545  }  }
# Line 729  Line 740 
740      return $retVal;      return $retVal;
741  }  }
742    
743    =head3 SkipIndicated
744    
745        my $flag = $edbl->SkipIndicated($section, \@tables);
746    
747    Return FALSE if the current group should be run for the current section.
748    If the C<resume> option is not set, this method always returns FALSE;
749    otherwise, it will look at the files currently in the load directory and
750    if enough of them are present, it will return TRUE, indicating there's
751    no point in generating data for the indicated tables with respect to the
752    current section. In other words, it will return TRUE if, for every table,
753    there is either a load file for that table or a load file for the
754    specified section of that table.
755    
756    =over 4
757    
758    =item section
759    
760    ID of the relevant section.
761    
762    =item tables
763    
764    List of tables to check.
765    
766    =item RETURN
767    
768    Returns TRUE if load files are already generated for the specified section, else FALSE.
769    
770    =back
771    
772    =cut
773    
774    sub SkipIndicated {
775        # Get the parameters.
776        my ($self, $section, $tables) = @_;
777        # Declare the return variable. It's FALSE if there's no resume parameter.
778        my $retVal = $self->{options}->{resume};
779        # Loop through the table names while $retval is TRUE.
780        for my $table (@$tables) { last if ! $retVal;
781            # Compute the file names.
782            my @files = map { ERDBGenerate::CreateFileName($table, $_, data => $self->{directory}) }
783                (undef, $section);
784            # If neither is present, we can't skip. So, if the grep below returns an empty
785            # list, we set $retVal FALSE, which stops the loop.
786            if (scalar(grep { -f $_ } @files) == 0) {
787                $retVal = 0;
788                Trace("Section $section not found for $table in $self->{group}. Regeneration required.") if T(3);
789            }
790        }
791        # Return the result.
792        return $retVal;
793    }
794    
795    
796  =head2 Virtual Methods  =head2 Virtual Methods
797    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.6

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3