#!/usr/bin/perl # Batch EXecutor 2.0 -- Insert to Queue # (c) 2011 Martin Mares use strict; use warnings; use Getopt::Long; use File::stat; use lib 'lib'; use BEX; my $queue_name; GetOptions( "q|queue=s" => \$queue_name, ) or die <] [!] ... Options: -q, --queue= Insert new jobs to the given queue AMEN # Prepare machine set @ARGV or die "No machines specified\n"; my @machines = BEX::Config::parse_machine_list(@ARGV); @machines or die "No machines match\n"; # Create job template and let the user edit it my $job = BEX::Job->new; my $fn = $job->save; my $orig_stat = stat($fn) or die; system "editor", $fn and die "Editor exited with an error, file kept as $fn\n"; my $new_stat = stat($fn) or die "File $fn disappeared under my hands: $!\n"; if ($new_stat->mtime <= $orig_stat->mtime && $new_stat->size == $orig_stat->size) { unlink $fn; die "Cancelled\n"; } # Re-load the job and put it to the queue $job = BEX::Job->new_from_file($fn); print "New job ", $job->id, "\n"; my $queue = BEX::Queue->new($queue_name); for my $m (@machines) { if ($queue->enqueue($m, $job)) { print "\t$m\n"; } else { print "\t$m (already queued)\n"; } } # Remove the temporary file unlink $fn;