From d15001c2761c9a0d988d421a1598d593fb83de35 Mon Sep 17 00:00:00 2001 From: miker Date: Sun, 21 Jan 2007 20:48:17 +0000 Subject: [PATCH] remove forking from local ingester git-svn-id: svn://svn.open-ils.org/ILS/trunk@6797 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/import/direct_ingest.pl | 102 ++++++++-------------------- 1 file changed, 29 insertions(+), 73 deletions(-) diff --git a/Open-ILS/src/extras/import/direct_ingest.pl b/Open-ILS/src/extras/import/direct_ingest.pl index 6fcae1ad1b..4159ff7ff5 100755 --- a/Open-ILS/src/extras/import/direct_ingest.pl +++ b/Open-ILS/src/extras/import/direct_ingest.pl @@ -26,13 +26,11 @@ use MARC::Charset; MARC::Charset->ignore_errors(1); -my ($auth, $workers, $config, $prefix) = - (0, 1, '/openils/conf/bootstrap.conf', 'marc-out-'); +my ($auth, $config) = + (0, '/openils/conf/bootstrap.conf'); GetOptions( - 'threads=i' => \$workers, 'config=s' => \$config, - 'prefix=s' => \$prefix, 'authority' => \$auth, ); @@ -44,76 +42,34 @@ select NEWERR; $| = 1; select STDERR; $| = 1; select STDOUT; $| = 1; -for (1 .. $workers) { - my ($r,$w); - pipe($r,$w); - if (fork) { - push @ses, $w; - } else { - $0 = "Local Ingest Worker $_"; - if ($workers == 1) { - worker($r, -1); - } else { - worker($r, $_); - } - exit; - } -} -$0 = "Local Ingest Master"; - -sub worker { - my $pipe = shift; - my $file = shift; - - OpenSRF::System->bootstrap_client( config_file => $config ); - Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); - - sleep 1; - - OpenILS::Application::Ingest->use; - - my $fname = "${prefix}$file"; - if ($file == -1) { - $fname = '&STDOUT'; - } - - my $f = new FileHandle(">$fname"); - - my $meth = 'open-ils.ingest.full.biblio.object.readonly'; - $meth = 'open-ils.ingest.full.authority.object.readonly' if ($auth); - - $meth = OpenILS::Application::Ingest->method_lookup( $meth ); +OpenSRF::System->bootstrap_client( config_file => $config ); +Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); - while (my $rec = <$pipe>) { +OpenILS::Application::Ingest->use; - my $bib = JSON->JSON2perl($rec); - my $data; +my $meth = 'open-ils.ingest.full.biblio.object.readonly'; +$meth = 'open-ils.ingest.full.authority.object.readonly' if ($auth); - try { - ($data) = $meth->run( $bib ); - } catch Error with { - my $e = shift; - warn "Couldn't process record: $e\n >>> $rec\n"; - }; - - next unless $data; - - postprocess( - { bib => $bib, - worm_data => $data, - }, - $f - ); - } -} +$meth = OpenILS::Application::Ingest->method_lookup( $meth ); my $count = 0; my $starttime = time; -while ( my $rec = <> ) { +while (my $rec = <>) { next unless ($rec); - my $session_index = $count % $workers; - $ses[$session_index]->printflush( $rec ); + my $bib = JSON->JSON2perl($rec); + my $data; + + try { + ($data) = $meth->run( $bib ); + } catch Error with { + my $e = shift; + warn "Couldn't process record: $e\n >>> $rec\n"; + }; + + next unless $data; + + postprocess( { bib => $bib, worm_data => $data } ); if (!($count % 20)) { print NEWERR "\r$count\t". $count / (time - $starttime); @@ -122,25 +78,25 @@ while ( my $rec = <> ) { $count++; } -$ses[$_]->close for (@ses); sub postprocess { my $data = shift; - my $f = shift; my $bib = $data->{bib}; - my $field_entries = $data->{worm_data}->{field_entries} unless ($auth); my $full_rec = $data->{worm_data}->{full_rec}; + + my $field_entries = $data->{worm_data}->{field_entries} unless ($auth); my $fp = $data->{worm_data}->{fingerprint} unless ($auth); my $rd = $data->{worm_data}->{descriptor} unless ($auth); $bib->fingerprint( $fp->{fingerprint} ) unless ($auth); $bib->quality( $fp->{quality} ) unless ($auth); - $f->printflush( JSON->perl2JSON($bib)."\n" ); + print( JSON->perl2JSON($bib)."\n" ); unless ($auth) { - $f->printflush( JSON->perl2JSON($rd)."\n" ); - $f->printflush( JSON->perl2JSON($_)."\n" ) for (@$field_entries); + print( JSON->perl2JSON($rd)."\n" ); + print( JSON->perl2JSON($_)."\n" ) for (@$field_entries); } - $f->printflush( JSON->perl2JSON($_)."\n" ) for (@$full_rec); + + print( JSON->perl2JSON($_)."\n" ) for (@$full_rec); } -- 2.11.0