From: Martin Mares Date: Fri, 21 Sep 2012 13:58:25 +0000 (+0200) Subject: bex queue: Implemented filtering of states, fixed --attn X-Git-Tag: v3.1~11 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=163dc9a6fb190d08e1d997a2695d4b61a0c4551c;p=bex.git bex queue: Implemented filtering of states, fixed --attn --- diff --git a/lib/bin/bex-queue b/lib/bin/bex-queue index d98f8dc..a109f70 100755 --- a/lib/bin/bex-queue +++ b/lib/bin/bex-queue @@ -18,6 +18,7 @@ my $attention; my $filenames; my $given_job; my $summary; +my $state_regex; my $why; sub usage() { @@ -31,11 +32,12 @@ Actions: --move-to= Move jobs to a different queue Options: --a, --attn Show jobs needing attention (e.g., failures) +-a, --attn Show only jobs needing attention (e.g., failures) -f, --filenames Show filenames of jobs and log files -j, --job= Act on the specified job (default: on all) -q, --queue= Act on the given queue -s, --summary Show only a summary +-S, --state= Act only on jobs whose state matches the given regex -w, --why[=] In case of failed jobs, display last few lines of output AMEN exit 0; @@ -52,6 +54,7 @@ GetOptions( "j|job=s" => \$given_job, "q|queue=s" => \$queue_name, "s|summary!" => \$summary, + "S|state=s" => \$state_regex, "w|why:i" => \$why, "help" => \&usage, ) or die "Try `bex queue --help' for more information.\n"; @@ -59,6 +62,18 @@ GetOptions( my @machines = BEX::Config::parse_machine_list(@ARGV ? @ARGV : '*'); my $queue = BEX::Queue->new($queue_name); +# Status cache +my %status_cache = (); +sub get_status($$) { + my ($m, $j) = @_; + $status_cache{$m}{$j} or $status_cache{$m}{$j} = $queue->read_job_status($m, $j); + return $status_cache{$m}{$j}; +} +sub get_stat($$) { + my ($m, $j) = @_; + return get_status($m, $j)->{'Status'} // 'UNKNOWN'; +} + # Select jobs my %jobs = (); my %machs = (); @@ -67,6 +82,12 @@ for my $m (@machines) { if (defined $given_job) { next if $j ne $given_job; } + if (defined $attention) { + next if get_stat($m, $j) =~ m{^(NEW|NOPING)$}; + } + if (defined $state_regex) { + next unless get_stat($m, $j) =~ m{^($state_regex)$}; + } push @{$jobs{$j}}, $m; push @{$machs{$m}}, $j; } @@ -94,9 +115,8 @@ sub do_ls() for my $m (keys %machs) { $mach_locked{$m} = $queue->is_locked($m, undef); for my $j (@{$machs{$m}}) { - my $st = $queue->read_job_status($m, $j); - my $s = $st->{"Status"} // "UNKNOWN"; - if ($attention) { next if $s =~ m{^(NEW|NOPING)$}; } + my $st = get_status($m, $j); + my $s = get_stat($m, $j); $cnt_by_job{$j}{$s}++; $cnt_by_mach{$m}{$s}++; $why{$m}{$j} = "";