]> mj.ucw.cz Git - bex.git/commitdiff
bex log: Added --why
authorMartin Mares <mares@kam.mff.cuni.cz>
Sat, 14 Apr 2012 13:46:26 +0000 (15:46 +0200)
committerroot <root@kam.mff.cuni.cz>
Sat, 14 Apr 2012 13:46:26 +0000 (15:46 +0200)
lib/bin/bex-queue

index 6f997d393958976f1ce521d9afc944cd1e848938..cfeb93058b7e1e708a981e811a07a662bf7f9a09 100755 (executable)
@@ -16,6 +16,7 @@ my $op_move_to;
 my $queue_name;
 my $given_job;
 my $summary;
+my $why;
 
 sub usage() {
        print <<AMEN ;
@@ -31,6 +32,7 @@ Options:
 -j, --job=<id>         Act on the specified job (default: on all)
 -q, --queue=<name>     Act on the given queue
 -s, --summary          Show only a summary
+-w, --why[=<lines>]    In case of failed jobs, display last few lines of output
 AMEN
        exit 0;
 }
@@ -44,6 +46,7 @@ GetOptions(
        "j|job=s" => \$given_job,
        "q|queue=s" => \$queue_name,
        "s|summary!" => \$summary,
+       "w|why:i" => \$why,
        "help" => \&usage,
 ) or die "Try `bex queue --help' for more information.\n";
 
@@ -81,6 +84,7 @@ sub do_ls()
        my %mach_locked = ();
        my %cnt_by_job = ();
        my %cnt_by_mach = ();
+       my %why = ();
        for my $m (keys %machs) {
                $mach_locked{$m} = $queue->is_locked($m, undef);
                for my $j (@{$machs{$m}}) {
@@ -91,6 +95,13 @@ sub do_ls()
                        if (defined($st->{'Time'}) && defined($st->{'Status'})) {
                                $stat{$m}{$j} = ' [' . $st->{'Status'} . ' on ' .
                                                POSIX::strftime('%Y-%m-%d', localtime $st->{'Time'}) . ']';
+                               if (defined($why) && $st->{'Status'} eq 'FAILED') {
+                                       my $lines = $why ? $why : 3;
+                                       my $log = $queue->log_file($m, $j);
+                                       if (-f $log) {
+                                               $why{$m}{$j} = join("", map { "\t\t>> $_" } `tail -n$lines $log`);
+                                       }
+                               }
                        } else {
                                $stat{$m}{$j} = '';
                        }
@@ -120,6 +131,7 @@ sub do_ls()
                                print "$m", ($mach_locked{$m} ? ' [LOCKED]' : ''), "\n";
                                for my $j (@{$machs{$m}}) {
                                        print "\t" . $queue->job_name($j) . $stat{$m}{$j}, "\n";
+                                       print $why{$m}{$j} // "";
                                }
                        }
                } else {
@@ -127,6 +139,7 @@ sub do_ls()
                                print $queue->job_name($j), "\n";
                                for my $m (sort @{$jobs{$j}}) {
                                        print "\t$m", $stat{$m}{$j}, "\n";
+                                       print $why{$m}{$j} // "";
                                }
                        }
                }