sub update($$$$) {
my ($ui, $mach, $jid, $stat) = @_;
- given ($stat) {
- when ('READY') {
+ for ($stat) {
+ if ($_ eq 'READY') {
# Pseudo-state generated internally
$ui->set_host_status($mach, 'ready');
$ui->set_job_status($mach, $jid, 'ready');
- }
- when ('OK') {
+ } elsif ($_ eq 'OK') {
$ui->set_job_status($mach, $jid, 'done');
- }
- when (['FAILED', 'INTERR', 'NOPING', 'PREPFAIL', 'NOXFER']) {
+ } elsif (/^(FAILED|INTERR|NOPING|PREPFAIL|NOXFER)$/) {
$ui->set_job_status($mach, $jid, 'failed');
$host_last_fail_job{$mach} = $jid;
$host_last_fail_stat{$mach} = $stat;
- }
- when ('DONE') {
+ } elsif ($_ eq 'DONE') {
if ($job_cnt{$mach}{'failed'}) {
$ui->set_host_status($mach, 'failed');
} else {
$ui->set_host_status($mach, 'done');
}
- }
- when ('INIT') {
+ } elsif ($_ eq 'INIT') {
$ui->set_host_status($mach, 'running');
$ui->set_job_status($mach, $jid, 'running') if defined $jid;
- }
- when ('LOCKED') {
+ } elsif ($_ eq 'LOCKED') {
if (defined $jid) {
$ui->set_job_status($mach, $jid, 'failed');
} else {
$host_last_fail_job{$mach} = $jid;
$host_last_fail_stat{$mach} = $stat;
}
- }
- when (['START', 'PING', 'PREP', 'SEND', 'RUN']) {
- }
- default {
+ } elsif (/^(START|PING|PREP|SEND|RUN)$/) {
+ } else {
$ui->err("Received unknown job status $stat");
}
}
sub lock($$$) {
my ($queue, $machine, $jid) = @_;
my $lock;
- given ($BEX::Config::locking_scheme) {
- when ('queue') {
+ for ($BEX::Config::locking_scheme) {
+ if ($_ eq 'queue') {
$lock = lock_name($queue, undef, undef);
- }
- when ('host') {
+ } elsif ($_ eq 'host') {
defined($machine) or return 1;
$lock = lock_name($queue, $machine, undef);
- }
- when ('job') {
+ } elsif ($_ eq 'job') {
defined($machine) && defined($jid) or return 1;
$lock = lock_name($queue, $machine, $jid);
+ } elsif ($_ eq 'none') {
+ return 1;
+ } else {
+ die "Invalid BEX::Config::locking_scheme";
}
- when ('none') { return 1; }
- default { die "Invalid BEX::Config::locking_scheme"; }
}
if (defined($queue->{'LockName'})) {
return 1 if ($queue->{'LockName'} eq $lock);
delete $queue->{'LockName'};
}
-# Unsafe (does not check fcntl, only existence of a lock file), but should be enough for `bex ls'
+# Unsafe (does not check fcntl, only existence of a lock file), but should be enough for `bex queue'
sub is_locked($$$) {
my ($queue, $machine, $jid) = @_;
- given ($BEX::Config::locking_scheme) {
+ for ($BEX::Config::locking_scheme) {
# Shortcuts
- when ('host') { return unless defined $machine; }
- when ('jid') { return unless defined $jid; }
- when ('none') { return; }
+ if ($_ eq 'host') { return unless defined $machine; }
+ elsif ($_ eq 'jid') { return unless defined $jid; }
+ elsif ($_ eq 'none') { return; }
}
my $lock = lock_name($queue, $machine, $jid);
return -f $lock;