From 4814654f645e18e0836c989fd7686d282a5c58ce Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 16 Feb 2012 17:33:20 +0100 Subject: [PATCH] add: When a job ID is reused, the old contents are overwritten --- lib/bin/bex-add | 1 + lib/perl/BEX/Queue.pm | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/bin/bex-add b/lib/bin/bex-add index 64945f9..6cfbd17 100755 --- a/lib/bin/bex-add +++ b/lib/bin/bex-add @@ -92,6 +92,7 @@ if (defined $requeue_id) { # Put the job to the queue print "New job ", $job->id, "\n"; +$queue->save_job($job); for my $m (@machines) { if ($queue->enqueue($m, $job)) { $queue->update_job_status($m, $job->id, 'NEW'); diff --git a/lib/perl/BEX/Queue.pm b/lib/perl/BEX/Queue.pm index acf537c..298c25d 100644 --- a/lib/perl/BEX/Queue.pm +++ b/lib/perl/BEX/Queue.pm @@ -73,14 +73,19 @@ sub job_file($$) { return $queue->{'Path'} . '/jobs/' . $jid. '.job'; } +sub save_job($$) { + my ($queue, $job) = @_; + # If the job already exists, it is shamelessly rewritten by new contents + $job->save($queue->job_file($job->id)); +} + sub enqueue($$$) { my ($queue, $machine, $job) = @_; + # The job must be already saved to the current queue my $qf = $queue->queue_file($machine, $job->id); if (-f $qf) { return 0; } - my $fn = $queue->job_file($job->id); - -f $fn or $job->save($fn); my $dir = $queue->host_dir($machine); -d $dir or mkdir $dir or die "Cannot create directory $dir: $!"; symlink '../../jobs/' . $job->id . '.job', $qf or die "Cannot create $qf: $!"; -- 2.39.5