From fe1705f947952fa5b4238c802f5d024cf3d7b7e1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 18 Nov 2020 10:36:43 +0000 Subject: [PATCH] Bug 27048: Add basic timekeeping to rebuild_zebra This patch adds a start time, end time and elapsed times on the 'records exported' lines to the verbose output of the rebuild_zebra.pl script. Test plan 1/ Run rebuild_zebra.pl -a -b -v 2/ Note the new timestamps included on the verbose output 3/ Signoff Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart --- misc/migration_tools/rebuild_zebra.pl | 35 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index cb42164e06..8fd611a83b 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -209,7 +209,9 @@ if( !defined $LockFH ) { # the lockfile) }; +my $start_time = time(); if ( $verbose_logging ) { + my $pretty_time = POSIX::strftime("%H:%M:%S",localtime($start_time)); print "Zebra configuration information\n"; print "================================\n"; print "Zebra biblio directory = $biblioserverdir\n"; @@ -219,6 +221,7 @@ if ( $verbose_logging ) { print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n"; print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n"; print "================================\n"; + print "Job started: $pretty_time\n"; } my $tester = XML::LibXML->new(); @@ -267,6 +270,8 @@ if ($daemon_mode) { if ( $verbose_logging ) { + print "====================\n"; + print "Indexing complete: ". pretty_time() . "\n"; print "====================\n"; print "CLEANING\n"; print "====================\n"; @@ -362,7 +367,7 @@ sub index_records { } else { if ( $verbose_logging ) { print "====================\n"; - print "exporting $record_type\n"; + print "exporting $record_type " . pretty_time() . "\n"; print "====================\n"; } mkdir "$directory" unless (-d $directory); @@ -403,7 +408,7 @@ sub index_records { } else { if ( $verbose_logging ) { print "====================\n"; - print "REINDEXING zebra\n"; + print "REINDEXING zebra " . pretty_time() . "\n"; print "====================\n"; } my $record_fmt = 'marcxml'; @@ -556,7 +561,7 @@ sub export_marc_records_from_sth { } } } - print "\nRecords exported: $num_exported\n" if ( $verbose_logging ); + print "\nRecords exported: $num_exported " . pretty_time() . "\n" if ( $verbose_logging ); print {$fh} $marcxml_close; close $fh; @@ -593,7 +598,7 @@ sub export_marc_records_from_list { } } } - print "\nRecords exported: $num_exported\n" if ( $verbose_logging ); + print "\nRecords exported: $num_exported " . pretty_time() . "\n" if ( $verbose_logging ); print {$fh} $marcxml_close; @@ -632,7 +637,7 @@ sub generate_deleted_marc_records { $records_deleted->{$record_number} = 1; } - print "\nRecords exported: $i\n" if ( $verbose_logging ); + print "\nRecords exported: $i " . pretty_time() . "\n" if ( $verbose_logging ); print {$fh} $marcxml_close; @@ -826,6 +831,26 @@ sub _create_lockfile { #returns undef on failure return ( $fh, $dir.'/'.LOCK_FILENAME ); } +sub pretty_time { + use integer; + my $now = time; + my $elapsed = $now - $start_time; + local $_ = $elapsed; + my ( $d, $h, $m, $s ); + $s = $_ % 60; + $_ /= 60; + $m = $_ % 60; + $_ /= 60; + $h = $_ % 24; + $_ /= 24; + $d = $_; + + my $now_pretty = POSIX::strftime("%H:%M:%S",localtime($now)); + my $elapsed_pretty = $d ? "[$d:$h:$m:$s]" : $h ? "[$h:$m:$s]" : $m ? "[$m:$s]" : "[$s]"; + + return "$now_pretty $elapsed_pretty"; +} + sub print_usage { print <<_USAGE_; $0: reindex MARC bibs and/or authorities in Zebra. -- 2.39.5