From 7d56f9ed1500c3d5bc9081a74cd30e621448bd0d Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 15 Feb 2012 23:39:46 +0100 Subject: [PATCH] Creation of queues must be explicit --- bex | 1 + lib/bin/queue | 33 +++++++++++++++++++++++++++++++++ lib/perl/BEX/Queue.pm | 8 +++----- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100755 lib/bin/queue diff --git a/bex b/bex index 237db3f..860dce9 100755 --- a/bex +++ b/bex @@ -27,6 +27,7 @@ job Operations on queued jobs ls (l) Show queues and jobs on them mach List known machines and groups prun (pr) Parallel version of `run' +queue Operations on queues run (r) Run queued jobs AMEN exit 0; diff --git a/lib/bin/queue b/lib/bin/queue new file mode 100755 index 0000000..2fb46fa --- /dev/null +++ b/lib/bin/queue @@ -0,0 +1,33 @@ +#!/usr/bin/perl +# Batch EXecutor 3.0 -- Operations on Queues +# (c) 2011-2012 Martin Mares + +use strict; +use warnings; +use Getopt::Long; +use BEX; + +my $init; + +GetOptions( + "init!" => \$init, +) && @ARGV == 1 or die <] + +Options: +--init Create a new queue +AMEN + +my $queue_name = shift @ARGV; + +if ($init) { + my $path = $BEX::Config::home . '/' . $queue_name; + -d $path and die "Queue directory $path already exists\n"; + mkdir $path; + mkdir "$path/hosts"; + mkdir "$path/jobs"; + print "Queue $queue_name initialized.\n"; +} else { + my $queue = BEX::Queue->new($queue_name); + print "Queue $queue is OK\n"; +} diff --git a/lib/perl/BEX/Queue.pm b/lib/perl/BEX/Queue.pm index b716509..36a19c5 100644 --- a/lib/perl/BEX/Queue.pm +++ b/lib/perl/BEX/Queue.pm @@ -16,10 +16,8 @@ sub new($;$) { my ($class, $name) = @_; $name //= 'queue'; my $path = $BEX::Config::home . '/' . $name; - -d $path or die "Queue directory $path does not exist\n"; - for my $d ("hosts", "jobs") { - -d "$path/$d" or mkdir "$path/$d" or die "Cannot create directory $path/$d: $!"; - } + -d $path or die "Queue directory $path does not exist (use bex queue --init to create it)\n"; + -d "$path/hosts" && -d "$path/jobs" or die "Queue directory $path is misconfigured\n"; my $queue = { 'Name' => $name, 'Path' => $path, @@ -235,7 +233,7 @@ sub unlock($) { delete $queue->{'LockName'}; } -# Unsafe (does not check fcntl, only existence of a lock file), but should be enough for bq +# Unsafe (does not check fcntl, only existence of a lock file), but should be enough for `bex ls' sub is_locked($$$) { my ($queue, $machine, $jid) = @_; given ($BEX::Config::locking_scheme) { -- 2.39.2