$HOST contains the name of the host. This is useful for
example if you want to transfer data to the host by rsync.
+Whenever a user command wants a job ID, it accepts any substring, as long as
+it is unique.
+
### Status files ###
Structure identical to job headers, but they do not contain a body.
#!/usr/bin/perl
# Batch EXecutor -- Master Program
-# (c) 2012 Martin Mares <mj@ucw.cz>
+# (c) 2012--2015 Martin Mares <mj@ucw.cz>
use strict;
use warnings;
Commands (and aliases):
add (a) Add new jobs to a queue
help Show this help
-job Operations on queued jobs
+job (j) Operations on jobs
mach List known machines and groups
prun (pr) Parallel version of `run'
qman Management of queues
my %aliases = (
'a' => 'add',
+ 'j' => 'job',
'p' => 'prun',
'q' => 'queue',
'r' => 'run',
if (defined($given_body) || defined($given_execute) || defined($given_id) || defined($given_subject) || defined($given_template)) {
die "Parameters of a requeued job cannot be changed\n";
}
- my $fn = $queue->job_file($requeue_id);
- -f $fn or die "Job $requeue_id not known\n";
+ my $id = $queue->resolve_job_id($requeue_id);
+ my $fn = $queue->job_file($id);
$job = BEX::Job->new_from_file($fn);
} else {
# Create job template
#!/usr/bin/perl
# Batch EXecutor -- Operations on a Job
-# (c) 2011-2012 Martin Mares <mj@ucw.cz>
+# (c) 2011-2015 Martin Mares <mj@ucw.cz>
use strict;
use warnings;
sub usage() {
print <<AMEN ;
-Usage: bex job [<options>] <job-id>
+Usage: bex job [<options>] [<job-id>]
Options:
-e, --edit Run editor on the given job (no locking)
"e|edit!" => \$edit,
"q|queue=s" => \$queue_name,
"help" => \&usage,
-) && @ARGV == 1 or die "Try `bex job --help' for more information.\n";
+) && @ARGV <= 1 or die "Try `bex job --help' for more information.\n";
my $queue = BEX::Queue->new($queue_name);
-my $fn = $queue->job_file($ARGV[0]);
--f $fn or die "No such job " . $ARGV[0] . "\n";
+
+if (!@ARGV) {
+ my @jobs = $queue->all_job_ids;
+ for (sort @jobs) {
+ print $_, "\n";
+ }
+ exit 0;
+}
+
+my $jid = $queue->resolve_job_id($ARGV[0]);
+my $fn = $queue->job_file($jid);
if ($edit) {
system "editor", $fn;
#!/usr/bin/perl
# Batch EXecutor -- Show Queued Jobs
-# (c) 2011-2013 Martin Mares <mj@ucw.cz>
+# (c) 2011-2015 Martin Mares <mj@ucw.cz>
use strict;
use warnings;
my @machines = BEX::Config::parse_machine_list(@ARGV ? @ARGV : '*');
my $queue = BEX::Queue->new($queue_name);
+$given_job = $queue->resolve_job_id($given_job) if defined $given_job;
# Status cache
my %status_cache = ();
my @machines = BEX::Config::parse_machine_list(@ARGV ? @ARGV : '*');
my $queue = BEX::Queue->new($queue_name);
+$given_job = $queue->resolve_job_id($given_job) if defined $given_job;
$queue->lock(undef, undef) or die "The queue is locked by another bex run, cannot continue.\n";
# Batch EXecutor -- Queues
-# (c) 2011-2013 Martin Mares <mj@ucw.cz>
+# (c) 2011-2015 Martin Mares <mj@ucw.cz>
use strict;
use warnings;
$job->save($queue->job_file($job->id));
}
+sub all_job_ids($) {
+ my ($queue) = @_;
+ opendir my $dir, $queue->{'Path'} . '/jobs' or die "Cannot open job directory: $!\n";
+ my @jobs = ();
+ while (readdir $dir) {
+ s{\.job$}{} or next;
+ push @jobs, $_;
+ }
+ closedir $dir;
+ return @jobs;
+}
+
+# Resolve a (possibly partial) job ID given by the user
+sub resolve_job_id($$) {
+ my ($queue, $name) = @_;
+ BEX::Job::check_id($name) or die "Invalid job ID $name\n";
+ if (-f $queue->job_file($name)) {
+ return $name;
+ }
+
+ my @candidates = map { index($_, $name) >= 0 ? $_ : () } $queue->all_job_ids();
+ @candidates or die "No job called $name exists\n";
+ @candidates == 1 or die "Partial job ID $name is not unique\n";
+ return $candidates[0];
+}
+
sub enqueue($$$) {
my ($queue, $machine, $job) = @_;
# The job must be already saved to the current queue