From 844a1fbea2b94dc34802099c5b13376f0fbfab1d Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 31 Mar 2016 11:39:49 -0400 Subject: [PATCH] LP 1768715: Add --pipe option to pingest.pl With this option, pingest.pl reads a list of record IDs from standard input, instead of running a query. This is useful if you have a custom query to output only certain records to reingest and you can pipe the output into pingest.pl. Signed-off-by: Jason Stephenson Signed-off-by: Bill Erickson --- Open-ILS/src/support-scripts/pingest.pl | 30 ++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/support-scripts/pingest.pl b/Open-ILS/src/support-scripts/pingest.pl index ed9f45e950..898dc1380c 100755 --- a/Open-ILS/src/support-scripts/pingest.pl +++ b/Open-ILS/src/support-scripts/pingest.pl @@ -37,6 +37,7 @@ my $start_id; # start processing at this bib ID. my $end_id; # stop processing when this bib ID is reached. my $max_duration; # max processing duration in seconds my $help; # show help text +my $opt_pipe; # Read record ids from STDIN. GetOptions( 'batch-size=i' => \$batch_size, @@ -47,6 +48,7 @@ GetOptions( 'skip-facets' => \$skip_facets, 'start-id=i' => \$start_id, 'end-id=i' => \$end_id, + 'pipe' => \$opt_pipe, 'max-duration=i' => \$max_duration, 'help' => \$help ); @@ -75,6 +77,10 @@ sub help { --end-id Stop processing when this record ID is reached + --pipe + Read record IDs to reingest from standard input. + This option conflicts with --start-id and/or --end-id. + --max-duration Stop processing after this many total seconds have passed. @@ -87,6 +93,12 @@ HELP help() if $help; +# Check for mutually exclusive options: +if ($opt_pipe && ($start_id || $end_id)) { + warn('Mutually exclusive options'); + help(); +} + my $where = "WHERE deleted = 'f'"; if ($start_id && $end_id) { $where .= " AND id BETWEEN $start_id AND $end_id"; @@ -130,9 +142,21 @@ sub duration_expired { # connect to your database. my $dbh = DBI->connect('DBI:Pg:'); -my $results = $dbh->selectall_arrayref($q); -foreach my $r (@$results) { - my $record = $r->[0]; +# Get the input records from either standard input or the database. +my @input; +if ($opt_pipe) { + while () { + # Want only numbers, one per line. + if ($_ =~ /([0-9]+)/) { + push(@input, $1); + } + } +} else { + @input = ($dbh->selectall_arrayref($q)); +} + +foreach my $r (@input) { + my $record = (ref($r)) ? $r->[0] : $r; push(@blist, $record); # separate list of browse-only ingest push(@$records, $record); if (++$count == $batch_size) { -- 2.43.2