]> mj.ucw.cz Git - bex.git/blob - benq
Bug fixes
[bex.git] / benq
1 #!/usr/bin/perl
2 # Batch EXecutor 2.0 -- Insert to Queue
3 # (c) 2011 Martin Mares <mj@ucw.cz>
4
5 use strict;
6 use warnings;
7 use Getopt::Long;
8 use File::stat;
9
10 use lib 'lib';
11 use BEX;
12
13 my $queue_name;
14
15 GetOptions(
16         "q|queue=s" => \$queue_name,
17 ) or die <<AMEN ;
18 Usage: benq [<options>] [!]<machine-or-class> ...
19
20 Options:
21 -q, --queue=<name>      Insert new jobs to the given queue
22 AMEN
23
24 # Prepare machine set
25 @ARGV or die "No machines specified\n";
26 my @machines = BEX::Config::parse_machine_list(@ARGV);
27 @machines or die "No machines match\n";
28
29 # Create job template and let the user edit it
30 my $job = BEX::Job->new;
31 my $fn = $job->save;
32 my $orig_stat = stat($fn) or die;
33 system "editor", $fn and die "Editor exited with an error, file kept as $fn\n";
34 my $new_stat = stat($fn) or die "File $fn disappeared under my hands: $!\n";
35 if ($new_stat->mtime <= $orig_stat->mtime && $new_stat->size == $orig_stat->size) {
36         unlink $fn;
37         die "Cancelled\n";
38 }
39
40 # Re-load the job and put it to the queue
41 $job = BEX::Job->new_from_file($fn);
42 print "New job ", $job->id, "\n";
43 my $queue = BEX::Queue->new($queue_name);
44 for my $m (@machines) {
45         if ($queue->enqueue($m, $job)) {
46                 print "\t$m\n";
47         } else {
48                 print "\t$m (already queued)\n";
49         }
50 }
51
52 # Remove the temporary file
53 unlink $fn;