2 # Batch EXecutor 3.0 -- Show Queued Jobs
3 # (c) 2011-2012 Martin Mares <mj@ucw.cz>
21 Usage: bex queue [<options and actions>] [[!]<machine-or-class> ...]
24 --by-job Show jobs sorted by job ID (default)
25 -h, --by-host Show jobs sorted by host
26 --rm Remove jobs from the queue
27 --move-to=<queue> Move jobs to a different queue
30 -j, --job=<id> Act on the specified job (default: on all)
31 -q, --queue=<name> Act on the given queue
37 "by-job!" => \$op_by_job,
38 "h|by-host!" => \$op_by_host,
40 "move-to=s" => \$op_move_to,
41 "j|job=s" => \$given_job,
42 "q|queue=s" => \$queue_name,
44 ) or die "Try `bex queue --help' for more information.\n";
46 my @machines = BEX::Config::parse_machine_list(@ARGV ? @ARGV : '*');
47 my $queue = BEX::Queue->new($queue_name);
52 for my $m (@machines) {
53 for my $j ($queue->scan($m)) {
54 if (defined $given_job) {
55 next if $j ne $given_job;
57 push @{$jobs{$j}}, $m;
58 push @{$machs{$m}}, $j;
66 my $ops = 0 + defined($op_by_host) + defined($op_by_job) + defined($op_rm) + defined($op_move_to);
67 if ($ops > 1) { die "Multiple actions are not allowed\n"; }
69 if ($op_rm) { do_rm(); }
70 elsif (defined $op_move_to) { do_move_to(); }
78 for my $m (keys %machs) {
79 $mach_locked{$m} = $queue->is_locked($m, undef);
80 for my $j (@{$machs{$m}}) {
81 my $st = $queue->read_job_status($m, $j);
82 if (defined($st->{'Time'}) && defined($st->{'Status'})) {
83 $stat{$m}{$j} = ' [' . $st->{'Status'} . ' on ' .
84 POSIX::strftime('%Y-%m-%d', localtime $st->{'Time'}) . ']';
88 if ($mach_locked{$m} || $queue->is_locked($m, $j)) {
89 $stat{$m}{$j} .= ' [LOCKED]';
94 if ($queue->is_locked(undef, undef)) {
95 print "### Queue lock present\n\n";
99 for my $m (sort keys %machs) {
100 print "$m", ($mach_locked{$m} ? ' [LOCKED]' : ''), "\n";
101 for my $j (@{$machs{$m}}) {
102 print "\t" . $queue->job_name($j) . $stat{$m}{$j}, "\n";
106 for my $j (sort keys %jobs) {
107 print $queue->job_name($j), "\n";
108 for my $m (sort @{$jobs{$j}}) {
109 print "\t$m", $stat{$m}{$j}, "\n";
118 for my $m (sort keys %machs) {
119 for my $j (sort @{$machs{$m}}) {
120 if (!$queue->lock($m, $j)) {
121 print STDERR "Cannot remove $m:", $queue->job_name($j), ", it is locked\n";
124 $queue->update_job_status($m, $j, 'REMOVED');
125 $queue->remove($m, $j);
126 print "Removed $m:", $queue->job_name($j), "\n";
137 my $dest = BEX::Queue->new($op_move_to);
138 $dest->{'Name'} ne $queue->{'Name'} or die "Moving to the same queue is not permitted\n";
139 for my $j (sort keys %jobs) {
140 my $job = BEX::Job->new_from_file($queue->job_file($j));
141 for my $m (sort @{$jobs{$j}}) {
142 if (!$queue->lock($m, $j)) {
143 print STDERR "Cannot move $m:", $queue->job_name($j), ", it is locked\n";
146 my $enq = $dest->enqueue($m, $job);
148 $dest->update_job_status($m, $job->id, 'NEW', 'Moved to this queue');
150 $dest->log($m, $job->id, 'REQUEUE', 'Moved to this queue');
152 $queue->update_job_status($m, $job->id, 'REMOVED', 'Moved from this queue');
153 $queue->remove($m, $j);
154 print "Moved $m:", $dest->job_name($j);
155 print " (already queued)" if !$enq;