Permalink
Browse files

added tail feature

  • Loading branch information...
1 parent 002decd commit c5037917e84afdc5d240b3cbaca99070c6eebdac @barbie committed Oct 22, 2012
Showing with 42 additions and 2 deletions.
  1. +42 −2 lib/CPAN/Testers/Data/Generator.pm
@@ -479,6 +479,20 @@ $self->_log("STOP REPARSE\n");
return 1;
}
+sub tail {
+ my ($self,$hash) = @_;
+ return unless($hash->{file});
+
+$self->_log("START TAIL\n");
+
+ my $guids = $self->get_tail_guids();
+ my $fh = IO::File->new($hash->{file},'a+') or die "Cannot read file [$hash->{file}]: $!";
+ print "$_\n" for(@$guids);
+ $fh->close;
+
+$self->_log("STOP TAIL\n");
+}
+
#----------------------------------------------------------------------------
# Private Methods
@@ -490,6 +504,24 @@ sub commit {
}
}
+sub get_tail_guids {
+ my $self = shift;
+
+ eval {
+ $guids = $self->{librarian}->search(
+ 'core.type' => 'CPAN-Testers-Report',
+ 'core.update_time' => { ">", 0 },
+ '-desc' => 'core.update_time',
+ '-limit' => $self->{poll_limit},
+ );
+ };
+
+ $self->_log(" ... Metabase Tail Failed [$@]\n") if($@);
+ $self->_log("Retrieved ".($guids ? scalar(@$guids) : 0)." guids\n");
+
+ return $guids;
+}
+
sub get_next_guids {
my ($self,$start) = @_;
my ($guids,$time);
@@ -1019,8 +1051,8 @@ sub _get_guid_list {
while(<$fh>) {
chomp;
my ($num) = (m/^([\da-z-]+)/i);
- if($guid =~ /^\d+$/) { push @ids, $guid }
- else { push @guids, $guid }
+ if($num =~ /^\d+$/) { push @ids, $num }
+ else { push @guids, $num }
}
$fh->close;
} else {
@@ -1452,6 +1484,10 @@ In addition, as per reparse, there is the option to exclude fields from parsing
checks, where they may be corrupted, and can be later amended using the
'cpanstats-update' tool.
+=item * tail
+
+Write to a file, the list of GUIDs returned from a tail request.
+
=back
=head2 Private Methods
@@ -1464,6 +1500,10 @@ To speed up the transaction process, a commit is performed every 500 inserts.
This method is used as part of the clean up process to ensure all transactions
are completed.
+=item * get_tail_guids
+
+Get the list of GUIDs as would be seen for a tail log.
+
=item * get_next_guids
Get the list of GUIDs for the reports that have been submitted since the last

0 comments on commit c503791

Please sign in to comment.