use warnings;
use DBI;
use Getopt::Long;
+use DateTime;
+use Sys::Syslog qw(syslog openlog);
# Globals for the command line options: --
my $max_duration; # max processing duration in seconds
my $newest_first; # Process records in descending order of edit_date
my $sort_id_desc; # Sort by record ID descending
+my $log_stdout; # Clone log messages to stdout
my $help; # show help text
+my $syslog_facility = 'LOCAL6'; # matches Evergreen gateway
+my $syslog_ops = 'pid';
+my $syslog_ident = 'pingest';
+
GetOptions(
'batch-size=i' => \$batch_size,
'max-child=i' => \$max_child,
'newest-first' => \$newest_first,
'sort-id-desc' => \$sort_id_desc,
'max-duration=i' => \$max_duration,
+ 'log-stdout' => \$log_stdout,
'help' => \$help
);
--max-id
Only process records whose ID is equal to or less than max-id.
+ --log-stdout
+ Clone debug and error messages to STDOUT. Beware that the
+ contents of 'print' calls from daemonized child process may not
+ reach STDOUT of the controlling terminal.
+
+ All messages are logged to syslog.
+
--help
Show this help text.
help() if $help;
+openlog($syslog_ident, $syslog_ops, $syslog_facility);
+
+# options for level match syslog options: DEBUG,INFO,WARNING,ERR
+sub announce {
+ my ($level, $msg, $die) = @_;
+ syslog("LOG_$level", "$level $msg");
+
+ my $date_str = DateTime->now(time_zone => 'local')->strftime('%F %T');
+ my $msg_str = "$date_str [$$] $level $msg\n";
+
+ if ($die) {
+ die $msg_str;
+
+ } else {
+ if ($level eq 'ERR' or $level eq 'WARNING') {
+ # always clone error messages to stdout
+ warn $msg_str; # avoid dupe messages
+ } elsif ($log_stdout) {
+ print $msg_str;
+ }
+ }
+}
+
+announce('DEBUG',
+ "pingest starting with batch-size $batch_size and max_child $max_child");
+
my $where = "WHERE deleted = 'f'";
if ($min_id && $max_id) {
$where .= " AND id BETWEEN $min_id AND $max_id";
if (grep {$_ == $pid} @running) {
@running = grep {$_ != $pid} @running;
$count++;
- print "$count of $lists processed\n";
+ announce('INFO', "$count of $lists processed");
}
}
if ($duration_expired && scalar(@running) == 0) {
- warn "Exiting on max_duration ($max_duration)\n";
+ announce('INFO', "Exiting on max_duration ($max_duration)");
exit(0);
}
}
if ($sth->execute($_)) {
my $crap = $sth->fetchall_arrayref();
} else {
- warn ("Browse ingest failed for record $_");
+ announce('WARNING', "Browse ingest failed for record $_");
}
if (duration_expired()) {
- warn "browse_ingest() stopping on record $_ ".
- "after max duration reached\n";
+ announce('INFO',
+ "browse_ingest() stopping on record $_ on max duration");
last;
}
}
if ($sth->execute()) {
my $crap = $sth->fetchall_arrayref();
} else {
- warn ("metabib.reingest_metabib_field_entries failed for record $_");
+ announce('WARNING',
+ "metabib.reingest_metabib_field_entries failed for record $_");
}
}
}
if ($sth->execute()) {
my $crap = $sth->fetchall_arrayref();
} else {
- warn ("metabib.reingest_record_attributes failed for record $_");
+ announce('WARNING',
+ "metabib.reingest_record_attributes failed for record $_");
}
}
}