]> mj.ucw.cz Git - bex.git/commitdiff
bq --job
authorMartin Mares <mj@ucw.cz>
Mon, 31 Oct 2011 12:10:00 +0000 (13:10 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 31 Oct 2011 12:10:00 +0000 (13:10 +0100)
bq

diff --git a/bq b/bq
index e35528a0a9a380dc5df20c86b6e1139f9389f06f..9be29ab965c21fa7c9516d5a8a97d9f58d8b6fd7 100755 (executable)
--- a/bq
+++ b/bq
@@ -12,25 +12,24 @@ use BEX;
 
 my $by_host;
 my $queue_name;
+my $given_job;
 
 GetOptions(
        "h|by-host!" => \$by_host,
+       "j|job=s" => \$given_job,
        "q|queue=s" => \$queue_name,
 ) or die <<AMEN ;
 Usage: bq [<options>] [[!]<machine-or-class> ...]
 
 Options:
 -h, --by-host          Show jobs sorted by host (default: by job)
+-j, --job=<id>         Show only instances of the specified job
 -q, --queue=<name>     Show jobs in the given queue
 AMEN
 
 my @machines = BEX::Config::parse_machine_list(@ARGV ? @ARGV : '*');
 my $queue = BEX::Queue->new($queue_name);
 
-if ($queue->is_locked(undef, undef)) {
-       print "### Queue lock present\n\n";
-}
-
 my %jobs = ();
 my %machs = ();
 my %subj = ();
@@ -39,10 +38,20 @@ my %mach_locked = ();
 for my $m (@machines) {
        $mach_locked{$m} = $queue->is_locked($m, undef);
        for my $j ($queue->scan($m)) {
+               if (defined $given_job) {
+                       next if $j ne $given_job;
+               }
                push @{$jobs{$j}}, $m;
                push @{$machs{$m}}, $j;
                my $job = $queue->job_metadata($j);
                $subj{$j} = ' (' . $job->{'Subject'} . ')';
+
+       }
+}
+
+# Read status of each job
+for my $m (keys %machs) {
+       for my $j (@{$machs{$m}}) {
                my $st = $queue->read_job_status($m, $j);
                if (defined($st->{'Time'}) && defined($st->{'Status'})) {
                        $stat{$m}{$j} = ' [' . $st->{'Status'} . ' on ' .
@@ -56,6 +65,10 @@ for my $m (@machines) {
        }
 }
 
+if ($queue->is_locked(undef, undef)) {
+       print "### Queue lock present\n\n";
+}
+
 if ($by_host) {
        for my $m (sort keys %machs) {
                print "$m", ($mach_locked{$m} ? ' [LOCKED]' : ''), "\n";