my $queue_name;
my $given_job;
my $summary;
+my $why;
sub usage() {
print <<AMEN ;
-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;
}
"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";
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}}) {
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} = '';
}
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 {
print $queue->job_name($j), "\n";
for my $m (sort @{$jobs{$j}}) {
print "\t$m", $stat{$m}{$j}, "\n";
+ print $why{$m}{$j} // "";
}
}
}