20 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
21 |
use File::Slurp; |
use File::Slurp; |
22 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
23 |
|
use Storable qw/dclone/; |
24 |
|
|
25 |
|
use Proc::Queue size => 1; |
26 |
|
use POSIX ":sys_wait_h"; # imports WNOHANG |
27 |
|
|
28 |
=head1 NAME |
=head1 NAME |
29 |
|
|
84 |
|
|
85 |
Force dump or input and marc record for debugging. |
Force dump or input and marc record for debugging. |
86 |
|
|
87 |
|
=item --parallel 4 |
88 |
|
|
89 |
|
Run databases in parallel (aproximatly same as number of processors in |
90 |
|
machine if you want to use full load) |
91 |
|
|
92 |
|
=item --only-links |
93 |
|
|
94 |
|
Create just links |
95 |
|
|
96 |
=back |
=back |
97 |
|
|
98 |
=cut |
=cut |
109 |
my ($marc_normalize, $marc_output); |
my ($marc_normalize, $marc_output); |
110 |
my $marc_lint = 1; |
my $marc_lint = 1; |
111 |
my $marc_dump = 0; |
my $marc_dump = 0; |
112 |
|
my $parallel = 0; |
113 |
|
my $only_links = 0; |
114 |
|
|
115 |
GetOptions( |
GetOptions( |
116 |
"limit=i" => \$limit, |
"limit=i" => \$limit, |
126 |
"marc-output=s" => \$marc_output, |
"marc-output=s" => \$marc_output, |
127 |
"marc-lint!" => \$marc_lint, |
"marc-lint!" => \$marc_lint, |
128 |
"marc-dump!" => \$marc_dump, |
"marc-dump!" => \$marc_dump, |
129 |
|
"parallel=i" => \$parallel, |
130 |
|
"only-links!" => \$only_links, |
131 |
); |
); |
132 |
|
|
133 |
$config = LoadFile($config); |
$config = LoadFile($config); |
159 |
my $start_t = time(); |
my $start_t = time(); |
160 |
|
|
161 |
my @links; |
my @links; |
162 |
my $indexer; |
|
163 |
|
if ($parallel) { |
164 |
|
$log->info("Using $parallel processes for speedup"); |
165 |
|
Proc::Queue::size($parallel); |
166 |
|
} |
167 |
|
|
168 |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
169 |
|
|
170 |
my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); |
my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); |
171 |
next if ($only_database && $database !~ m/$only_database/i); |
next if ($only_database && $database !~ m/$only_database/i); |
172 |
|
|
173 |
|
if ($parallel) { |
174 |
|
my $f=fork; |
175 |
|
if(defined ($f) and $f==0) { |
176 |
|
$log->info("Created processes $$ for speedup"); |
177 |
|
} else { |
178 |
|
next; |
179 |
|
} |
180 |
|
} |
181 |
|
|
182 |
|
my $indexer; |
183 |
if ($use_indexer) { |
if ($use_indexer) { |
184 |
my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration"); |
my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration"); |
185 |
$indexer_config->{database} = $database; |
$indexer_config->{database} = $database; |
208 |
|
|
209 |
|
|
210 |
# |
# |
211 |
|
# store Hyper Estraier links to other databases |
212 |
|
# |
213 |
|
if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) { |
214 |
|
foreach my $link (@{ $db_config->{links} }) { |
215 |
|
if ($use_indexer eq 'hyperestraier') { |
216 |
|
$log->info("saving link $database -> $link->{to} [$link->{credit}]"); |
217 |
|
push @links, sub { |
218 |
|
$log->info("adding link $database -> $link->{to} [$link->{credit}]"); |
219 |
|
$indexer->add_link( |
220 |
|
from => $database, |
221 |
|
to => $link->{to}, |
222 |
|
credit => $link->{credit}, |
223 |
|
); |
224 |
|
}; |
225 |
|
} else { |
226 |
|
$log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]"); |
227 |
|
} |
228 |
|
} |
229 |
|
} |
230 |
|
next if ($only_links); |
231 |
|
|
232 |
|
|
233 |
|
# |
234 |
# now WebPAC::Store |
# now WebPAC::Store |
235 |
# |
# |
236 |
my $abs_path = abs_path($0); |
my $abs_path = abs_path($0); |
300 |
}, |
}, |
301 |
recode => $input->{recode}, |
recode => $input->{recode}, |
302 |
stats => $stats, |
stats => $stats, |
303 |
|
modify_records => $input->{modify_records}, |
304 |
); |
); |
305 |
$log->logdie("can't create input using $input_module") unless ($input); |
$log->logdie("can't create input using $input_module") unless ($input); |
306 |
|
|
357 |
$log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors); |
$log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors); |
358 |
} |
} |
359 |
|
|
360 |
|
my $ds_config = dclone($db_config); |
361 |
|
|
362 |
|
# default values -> database key |
363 |
|
$ds_config->{_} = $database; |
364 |
|
|
365 |
|
# current mfn |
366 |
|
$ds_config->{_mfn} = $mfn; |
367 |
|
|
368 |
|
# attach current input |
369 |
|
$ds_config->{input} = $input; |
370 |
|
|
371 |
my $ds = WebPAC::Normalize::data_structure( |
my $ds = WebPAC::Normalize::data_structure( |
372 |
row => $row, |
row => $row, |
373 |
rules => $rules, |
rules => $rules, |
374 |
lookup => $lookup ? $lookup->lookup_hash : undef, |
lookup => $lookup ? $lookup->lookup_hash : undef, |
375 |
|
config => $ds_config, |
376 |
marc_encoding => 'utf-8', |
marc_encoding => 'utf-8', |
377 |
); |
); |
378 |
|
|
425 |
) |
) |
426 |
); |
); |
427 |
|
|
428 |
# |
|
429 |
# add Hyper Estraier links to other databases |
# end forked process |
430 |
# |
if ($parallel) { |
431 |
if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) { |
$log->info("parallel process $$ finished"); |
432 |
foreach my $link (@{ $db_config->{links} }) { |
exit(0); |
|
if ($use_indexer eq 'hyperestraier') { |
|
|
$log->info("saving link $database -> $link->{to} [$link->{credit}]"); |
|
|
push @links, { |
|
|
from => $database, |
|
|
to => $link->{to}, |
|
|
credit => $link->{credit}, |
|
|
}; |
|
|
} else { |
|
|
$log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]"); |
|
|
} |
|
|
} |
|
433 |
} |
} |
434 |
|
|
435 |
} |
} |
436 |
|
|
437 |
|
if ($parallel) { |
438 |
|
# wait all children to finish |
439 |
|
sleep(1) while wait != -1; |
440 |
|
$log->info("all parallel processes finished"); |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
foreach my $link (@links) { |
foreach my $link (@links) { |
445 |
$log->info("adding link $link->{from} -> $link->{to} [$link->{credit}]"); |
$log->logdie("coderef in link ", Dumper($link), " is ", ref($link), " and not CODE") unless (ref($link) eq 'CODE'); |
446 |
$indexer->add_link( %{ $link } ); |
$link->(); |
447 |
} |
} |
448 |
|
|