[Bps-public-commit] r15576 - in sd/branches/sd-trunk: lib/App/SD/Replica/rt

jesse at bestpractical.com jesse at bestpractical.com
Wed Aug 27 21:24:28 EDT 2008


Author: jesse
Date: Wed Aug 27 21:24:27 2008
New Revision: 15576

Modified:
   sd/branches/sd-trunk/   (props changed)
   sd/branches/sd-trunk/Makefile.PL
   sd/branches/sd-trunk/lib/App/SD/Replica/rt/PullEncoder.pm

Log:
 r44633 at 192:  jesse | 2008-08-27 16:23:22 -0700
 * Use Time::Progress to report how we're doing at walking RT ticket history


Modified: sd/branches/sd-trunk/Makefile.PL
==============================================================================
--- sd/branches/sd-trunk/Makefile.PL	(original)
+++ sd/branches/sd-trunk/Makefile.PL	Wed Aug 27 21:24:27 2008
@@ -4,7 +4,7 @@
 copyright('2008 Best Practical Solutions, LLC');
 license('MIT');
 version_from('lib/App/SD.pm');
-
+requires('Time::Progress');
 requires 'Prophet'; # URI UNIVERSAL::require Params::Validate Path::Class Class::Accessor
 requires('Moose'); # Moose::Role
 requires('HTTP::Date');

Modified: sd/branches/sd-trunk/lib/App/SD/Replica/rt/PullEncoder.pm
==============================================================================
--- sd/branches/sd-trunk/lib/App/SD/Replica/rt/PullEncoder.pm	(original)
+++ sd/branches/sd-trunk/lib/App/SD/Replica/rt/PullEncoder.pm	Wed Aug 27 21:24:27 2008
@@ -4,6 +4,7 @@
 
 use Params::Validate qw(:all);
 use Memoize;
+use Time::Progress;
 
 has sync_source => 
     ( isa => 'App::SD::Replica::rt',
@@ -24,14 +25,22 @@
     my $tickets = {};
     my @transactions;
 
-    my @tickets =  $self->find_matching_tickets( $args{'query'} ); 
+    $self->sync_source->log( "Finding tickets matching " . $args{'query'} );
+    my @tickets = $self->find_matching_tickets( $args{'query'} );
 
     $self->sync_source->log("No tickets found.") if @tickets == 0;
 
     my $counter = 0;
-    for my $id ( @tickets) {
+    $self->sync_source->log("Discovering ticket history");
+    my $progress = Time::Progress->new();
+    $progress->attr( max => $#tickets );
+    local $| = 1;
+    for my $id (@tickets) {
         $counter++;
-        $self->sync_source->log("Fetching ticket $id - $counter of ".scalar @tickets);
+        print $progress->report( "%30b %p Est: %E\r", $counter );
+
+        $self->sync_source->log(
+            "Fetching ticket $id - $counter of " . scalar @tickets );
         $tickets->{$id}->{ticket} = $self->_translate_final_ticket_state(
             $self->sync_source->rt->show( type => 'ticket', id => $id ) );
         push @transactions,
@@ -42,21 +51,26 @@
             )
             };
     }
-        my $txn_counter = 0;
-        my @changesets;
-        for my $txn ( sort { $b->{'id'} <=> $a->{'id'} } @transactions ) {
-            $txn_counter++;
-            $self->sync_source->log("Transcoding transaction  @{[$txn->{'id'}]} - $txn_counter of ". scalar @transactions);
-            my $changeset = $self->transcode_one_txn( $txn, $tickets->{ $txn->{Ticket} }->{ticket} );
-            next unless $changeset->has_changes;
-            unshift @changesets, $changeset;
-        }
+    my $txn_counter = 0;
+    my @changesets;
+    for my $txn ( sort { $b->{'id'} <=> $a->{'id'} } @transactions ) {
+        $txn_counter++;
+        $self->sync_source->log(
+            "Transcoding transaction  @{[$txn->{'id'}]} - $txn_counter of "
+                . scalar @transactions );
+        my $changeset = $self->transcode_one_txn( $txn,
+            $tickets->{ $txn->{Ticket} }->{ticket} );
+        next unless $changeset->has_changes;
+        unshift @changesets, $changeset;
+    }
 
-    my $cs_counter = 0;
-            for ( @changesets ) {
-    $self->sync_source->log("Applying changeset ".++$cs_counter . " of ".scalar @changesets); 
-            $args{callback}->($_)
-        }
+    my $cs_counter = 0 ;
+    for (@changesets) {
+        $self->sync_source->log( "Applying changeset "
+                . ++$cs_counter . " of "
+                . scalar @changesets );
+        $args{callback}->($_);
+    }
 
 }
 



More information about the Bps-public-commit mailing list