5 use lib '/openils/lib/perl5/';
8 use OpenSRF::EX qw/:try/;
9 use OpenSRF::AppSession;
10 use OpenSRF::Application;
11 use OpenSRF::MultiSession;
12 use OpenSRF::Utils::SettingsClient;
13 use OpenILS::Application::Ingest;
14 use OpenILS::Application::AppUtils;
15 use OpenILS::Utils::Fieldmapper;
16 use Digest::MD5 qw/md5_hex/;
21 use Time::HiRes qw/time/;
27 MARC::Charset->ignore_errors(1);
29 my ($auth, $workers, $config, $prefix) =
30 (0, 1, '/openils/conf/bootstrap.conf', 'marc-out-');
33 'threads=i' => \$workers,
34 'config=s' => \$config,
35 'prefix=s' => \$prefix,
36 'authority' => \$auth,
41 open NEWERR, ">&STDERR";
43 select NEWERR; $| = 1;
44 select STDERR; $| = 1;
45 select STDOUT; $| = 1;
53 $0 = "Local Ingest Worker $_";
62 $0 = "Local Ingest Master";
68 OpenSRF::System->bootstrap_client( config_file => $config );
69 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
73 OpenILS::Application::Ingest->use;
75 my $fname = "${prefix}$file";
80 my $f = new FileHandle(">$fname");
82 my $meth = 'open-ils.ingest.full.biblio.object.readonly';
83 $meth = 'open-ils.ingest.full.authority.object.readonly' if ($auth);
85 $meth = OpenILS::Application::Ingest->method_lookup( $meth );
87 while (my $rec = <$pipe>) {
89 my $bib = JSON->JSON2perl($rec);
93 ($data) = $meth->run( $bib );
96 warn "Couldn't process record: $e\n >>> $rec\n";
111 my $starttime = time;
112 while ( my $rec = <> ) {
114 my $session_index = $count % $workers;
116 $ses[$session_index]->printflush( $rec );
118 if (!($count % 20)) {
119 print NEWERR "\r$count\t". $count / (time - $starttime);
125 $ses[$_]->close for (@ses);
130 my $bib = $data->{bib};
131 my $field_entries = $data->{worm_data}->{field_entries} unless ($auth);
132 my $full_rec = $data->{worm_data}->{full_rec};
133 my $fp = $data->{worm_data}->{fingerprint} unless ($auth);
134 my $rd = $data->{worm_data}->{descriptor} unless ($auth);
136 $bib->fingerprint( $fp->{fingerprint} ) unless ($auth);
137 $bib->quality( $fp->{quality} ) unless ($auth);
139 $f->printflush( JSON->perl2JSON($bib)."\n" );
141 $f->printflush( JSON->perl2JSON($rd)."\n" );
142 $f->printflush( JSON->perl2JSON($_)."\n" ) for (@$field_entries);
144 $f->printflush( JSON->perl2JSON($_)."\n" ) for (@$full_rec);