Skip to content

Commit

Permalink
cannot quickly tell what is wrong with the tidy version, so reverting…
Browse files Browse the repository at this point in the history
… to untidy version, which is at least error free
  • Loading branch information
mwarin committed Jun 13, 2024
1 parent 2c0fc06 commit 345f11c
Showing 1 changed file with 74 additions and 97 deletions.
171 changes: 74 additions & 97 deletions bin/ingest_status.pl
Original file line number Diff line number Diff line change
@@ -1,169 +1,142 @@
#!/usr/bin/perl

use warnings;
use strict;

use FindBin;
use lib "$FindBin::Bin/../lib";

use Getopt::Long qw(:config no_ignore_case);
use HTFeed::DBTools qw(get_dbh);
use warnings;
use strict;
use HTFeed::Log { root_logger => 'INFO, screen' };
use HTFeed::Version;
use HTFeed::DBTools qw(get_dbh);
use HTFeed::Volume;
use Getopt::Long qw(:config no_ignore_case);
use Pod::Usage;

my $one_line = 0; # -1
my $verbose = 0; # -v
my $quiet = 0; # -q
my $status = undef; # -s
my $one_line = 0; # -1
my $verbose = 0; # -v
my $quiet = 0; # -q
my $status = undef; # -s
my $not_status = undef; # -S
my $help = 0; # -help,-?
my $dot = 0;
my $help = 0; # -help,-?
my $dot = 0;

my $default_namespace = undef; # -n

# read flags
GetOptions(
'1' => \$one_line,
'verbose|v' => \$verbose,
'status|s=s' => \$status,
'1' => \$one_line,
'verbose|v' => \$verbose,
'status|s=s' => \$status,
'not-status|S=s' => \$not_status,
'quiet|q' => \$quiet,
'dot|d' => \$dot,
'help|?' => \$help,
'namespace|n=s' => \$default_namespace,
) or pod2usage(2);
'quiet|q' => \$quiet,
'dot|d' => \$dot,
'help|?' => \$help,
'namespace|n=s' => \$default_namespace,
) or pod2usage(2);

pod2usage(1) if $help;

# check options
if ($default_namespace) and ($one_line or $dot) {
pod2usage(
-msg => '-n excludes -d and -1',
-exitval => 2
);
}
pod2usage(-msg => '-n excludes -d and -1', -exitval => 2) if ($default_namespace) and ($one_line or $dot);

my @volumes;

# handle -1 flag (no infile read, get one object form command line)
if ($one_line and $dot) {
if($one_line and $dot) {
my $htid = shift @ARGV;
my ($namespace, $objid) = parse_htid($htid);
push (
@volumes,
HTFeed::Volume->new(
packagetype => 'ht',
namespace => $namespace,
objid => $objid
)
);
} elsif ($one_line) {
push @volumes, HTFeed::Volume->new(packagetype => 'ht', namespace => $namespace, objid => $objid);
}
elsif ($one_line) {
my $namespace = shift @ARGV;
my $objid = shift @ARGV;
unless ($namespace and $objid) {
my $objid = shift @ARGV;
unless( $namespace and $objid ){
die 'Must specify namespace and objid when using -1 option';
}
push(
@volumes,
HTFeed::Volume->new(
packagetype => 'ht',
namespace => $namespace,
objid => $objid
)
);
} else {

push @volumes, HTFeed::Volume->new(packagetype => 'ht', namespace => $namespace, objid => $objid);
}
else{
# handle -d (read infile in dot format)
if ($dot) {
while (my $htid = <>) {
my ($namespace, $objid) = parse_htid($htid);
push(
@volumes,
HTFeed::Volume->new(
packagetype => 'ht',
namespace => $namespace,
objid => $objid
)
);
my ($namespace,$objid) = parse_htid($htid);

push @volumes, HTFeed::Volume->new(packagetype => 'ht', namespace => $namespace, objid => $objid);
}
}

# handle default case (read infile in standard format)
if (!$dot) {
if (! $dot) {
while (<>) {
next if ($_ =~ /^\s*$/); # skip blank line
my @words = split;
my $objid = pop @words;
my @words = split;
my $objid = pop @words;
my $namespace = (pop @words or $default_namespace);

die("namespace missing (specify with -n) (objid was $objid)\n") if not defined $namespace;
next if !$objid;

eval {
push(
@volumes,
HTFeed::Volume->new(
packagetype => 'ht',
namespace => $namespace,
objid => $objid
)
);
push @volumes, HTFeed::Volume->new(packagetype => 'ht', namespace => $namespace, objid => $objid);
};
if ($@) {
if($@) {
warn($@);
}
}
}
}

my $dbh = get_dbh();
my $log_sth = $dbh->prepare("select * from feed_log where namespace = ? and id = ? order by timestamp asc");
my $last_err_sth = $dbh->prepare("select * from feed_last_error where namespace = ? and id = ?");
my $queue_sth = $dbh->prepare("select * from feed_queue where namespace = ? and id = ?");

my $log_sth = $dbh->prepare("select * from feed_log where namespace = ? and id = ? order by timestamp asc");
my $last_err_sth = $dbh->prepare("select * from feed_last_error where namespace = ? and id = ?");
my $queue_sth = $dbh->prepare("select * from feed_queue where namespace = ? and id = ?");
my $queue_done_sth = $dbh->prepare("select * from feed_queue_done where namespace = ? and id = ?");

foreach my $volume (@volumes) {

my $namespace = $volume->get_namespace();
my $objid = $volume->get_objid();
$queue_sth->execute($namespace, $objid);
$queue_done_sth->execute($namespace, $objid);
my $queue_info = $queue_sth->fetchrow_hashref();
my $objid = $volume->get_objid();

$queue_sth->execute($namespace,$objid);
my $queue_info = $queue_sth->fetchrow_hashref();
$queue_done_sth->execute($namespace,$objid);
my $queue_done_info = $queue_done_sth->fetchrow_hashref();

if (not defined $queue_info) {
if (defined $queue_done_info) {
$queue_info = $queue_done_info;
$queue_info->{status} = 'done';
} else {
print "$namespace.$objid: not in queue\n" ;
next;
}
if(not defined $queue_info) {
if(defined $queue_done_info) {
$queue_info = $queue_done_info;
$queue_info->{status} = 'done';
} else {
print "$namespace.$objid: not in queue\n" ;
next;
}
}

next unless !$status or ($status eq $queue_info->{status});
next unless !$not_status or ($not_status ne $queue_info->{status});
next unless !$status or $status eq $queue_info->{status};
next unless !$not_status or $not_status ne $queue_info->{status};

print "$namespace.$objid: $queue_info->{pkg_type}; $queue_info->{status}";

if ($quiet) {
print "\n";
} else {
if(!$quiet) {
my $err_sth;
print " at $queue_info->{update_stamp}\n" if(!$quiet);

if ($verbose) {
if($verbose) {
$err_sth = $log_sth;
} elsif ($queue_info->{status} eq 'punted') {
}
elsif($queue_info->{status} eq 'punted') {
$err_sth = $last_err_sth;
}

if (defined $err_sth) {
$err_sth->execute($namespace, $objid);
while (my $row = $err_sth->fetchrow_hashref()) {
if(defined $err_sth) {
$err_sth->execute($namespace,$objid);
while(my $row = $err_sth->fetchrow_hashref()) {
print " ";
delete $row->{namespace};
delete $row->{id};
if ($verbose) {
if($verbose) {
print "$row->{timestamp} $row->{level}: ";
}
delete $row->{timestamp};
Expand All @@ -173,24 +146,28 @@
print "$row->{detail}; " if defined $row->{detail} and $row->{detail};
delete $row->{detail};
foreach my $key (sort(keys(%$row))) {

next if not defined $row->{$key} or $row->{$key} eq '';
print "$key: $row->{$key}; ";
}
print "\n";
}
}
} else {
print "\n";
}

}

sub parse_htid {
my $htid = shift;
# simplified, lines should match /(.*)\.(.*)/
$htid =~ /^([^\.\s]*)\.([^\s]*)$/;
my ($namespace, $objid) = ($1, $2);
unless ($namespace and $objid) {
my ($namespace,$objid) = ($1,$2);
unless( $namespace and $objid ){
die "Bad syntax near: $htid";
}
return($namespace, $objid);
return($namespace,$objid);
}

__END__
Expand Down Expand Up @@ -230,5 +207,5 @@ =head1 SYNOPSIS
dot-style (-d) infile rows:
namespace.objid
=cut

0 comments on commit 345f11c

Please sign in to comment.