IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2026, 4:53:16 PM (7 weeks ago)
Author:
eugene
Message:

working on modernizing the error_code trapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pstamp-20260421/pstamp/scripts/pstamp_queue_requests.pl

    r42981 r43048  
    1111
    1212use Getopt::Long qw( GetOptions );
     13use Scalar::Util qw(looks_like_number);
    1314
    1415use Sys::Hostname;
     
    7778    $command .= " -dbserver $dbserver" if $dbserver;
    7879
    79     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     80    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    8081        run(command => $command, verbose => $verbose);
     82    my $error_code = &parse_error_message ($success, $error_msg, $command);
    8183    unless ($success) {
    82         my $rc = $error_code >> 8;
     84        my $rc = $error_code;
    8385        die("Unable to perform pstamptool -datastore: $rc");
    8486    }
     
    121123        $command .= " --timeout $timeout";
    122124
    123         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     125        my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    124126            run(command => $command, verbose => $verbose);
     127        my $error_code = &parse_error_message ($success, $error_msg, $command);
    125128        unless ($success) {
    126129            # dsproductls exit status is the http error code - 300
    127             my $exit_status = $error_code >> 8;
     130            my $exit_status = $error_code;
    128131
    129132            # don't die on "common faults"
     
    167170        {
    168171            my $command = "$dsfilesetls --uri $uri";
    169             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     172            my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    170173                    run(command => $command, verbose => $verbose);
     174            my $error_code = &parse_error_message ($success, $error_msg, $command);
    171175            unless ($success) {
    172176                # we don't want to die here. We need to set lastFileset
     
    197201                $command .= " -dbserver $dbserver" if $dbserver;
    198202
    199                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     203                my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    200204                        run(command => $command, verbose => $verbose);
     205                my $error_code = &parse_error_message ($success, $error_msg, $command);
    201206
    202207                unless ($success) {
     
    208213
    209214        {
    210         ## now update the last_fileset column in pstampDataStore
    211         my $command = "$pstamptool -ds_id $ds_id -moddatastore -set_last_fileset $lastFileset";
    212         $command .= " -dbname $dbname" if $dbname;
    213         $command .= " -dbserver $dbserver" if $dbserver;
    214         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    215             run(command => $command, verbose => $verbose);
    216             unless ($success) {
    217                 die("Unable to perform pstamptool -moddatastore: $error_code");
    218             }
     215            ## now update the last_fileset column in pstampDataStore
     216            my $command = "$pstamptool -ds_id $ds_id -moddatastore -set_last_fileset $lastFileset";
     217            $command .= " -dbname $dbname" if $dbname;
     218            $command .= " -dbserver $dbserver" if $dbserver;
     219            my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
     220                run(command => $command, verbose => $verbose);
     221            my $error_code = &parse_error_message ($success, $error_msg, $command);
     222            unless ($success) {
     223                die("Unable to perform pstamptool -moddatastore: $error_code");
     224            }
    219225        }
    220226        last if ($numFilesets >= $limit);
     
    232238                $command .= " -dbname $dbname" if $dbname;
    233239                $command .= " -dbserver $dbserver" if $dbserver;
    234     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     240    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    235241        run(command => $command, verbose => $verbose);
     242    my $error_code = &parse_error_message ($success, $error_msg, $command);
    236243    unless ($success) {
    237244        die("Unable to perform pstamptool -moddatastore: $error_code");
    238245    }
    239246}
     247
     248# if the program exited normally, the exit value is returned
     249# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     250# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     251sub parse_error_message {
     252    my $success = shift;
     253    my $error_msg = shift;
     254    my $command = shift;
     255
     256    if ($success) { return 0; }
     257
     258    print "raw error_msg: $error_msg\n";
     259    print "full command: $command\n";
     260
     261    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     262       
     263    # which of these match?
     264    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     265    if (defined $error_code) { return $error_code; }
     266   
     267    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     268#   if (defined $error_code) { return (128 + $error_code); }
     269    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     270   
     271    # probably failed to execute:
     272    return (-1*$PS_EXIT_PROG_ERROR);
     273}
Note: See TracChangeset for help on using the changeset viewer.